Click here to Skip to main content
15,887,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good Afternoon,

I am trying to run a Diskpart script which will create new partitions for a Windows 7 image deployment. I have been having trouble with switching drives and running the script. I am using a cmd.exe process to run diskpart. The cmd window starts in C:\ and I need to change it to E:\, and then run the script. I have tried several items without luck. I also had it directing the output to a textbox. I provided my function below, which has some of the things i tried commented out. If someone could please help, I would greatly appreciate it.

If you need anything else, please let me know.

code:
VB
Private Sub CreatePartitions()
        'txtResults.Clear()
        ' If Me.InvokeRequired Then
        'Me.Invoke(New DelegateCreatePartitions(AddressOf CreatePartitions))
        'Else
        Dim tmp As String
        Dim myprocess1 As New Process
        Dim StartInfo As New System.Diagnostics.ProcessStartInfo
        'StartInfo.FileName = sSystem32 & "\diskpart.exe"
        StartInfo.FileName = sSystem32 & "\cmd.exe"
        ' StartInfo.Arguments = sBootLetter & "\diskpart.exe /s createpartitions.txt"
        ' StartInfo.CreateNoWindow = True
        StartInfo.RedirectStandardInput = True
        'StartInfo.RedirectStandardOutput = True
        StartInfo.UseShellExecute = False
        myprocess1.StartInfo = StartInfo
        myprocess1.Start()
        'myprocess1.WaitForExit()
        'Dim SR As System.IO.StreamReader = myprocess1.StandardOutput
        Dim SW As System.IO.StreamWriter = myprocess1.StandardInput
        SW.WriteLine(sBootLetter)
        SW.WriteLine("diskpart /s createpartitions.txt")
        'Do While myprocess1.HasExited = False
        ' tmp = SR.ReadLine & vbCrLf
        ' If tmp <> "" Then
        ' Me.txtResults.AppendText(tmp)
        ' End If
        ' Loop
        lblUpdateStatus.Text = "Partitions Created"
        SW.Close()
        ' SR.Close()
        'End If
    End Sub
Posted

1 solution

The command line for running something from CMD.EXE is:
CMD /C yourCommandLine


In your case, you're missing the "/C" switch for the CMD.EXE arguments. Your command line should be this:
CMD /C E:\diskpart.exe /s createpartitions.txt
 
Share this answer
 
Comments
iismoove 2-Apr-13 15:21pm    
I don't know how I could miss something like that! LOL. Thanks so much! I am going to give it try now.
dc4444 17-Jul-14 16:31pm    
Do you happen to have the complete solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900