Click here to Skip to main content
11,812,712 members (73,045 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB VB.NET Process
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.

Private Sub CreatePartitions()
        ' If Me.InvokeRequired Then
        'Me.Invoke(New DelegateCreatePartitions(AddressOf CreatePartitions))
        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
        'Dim SR As System.IO.StreamReader = myprocess1.StandardOutput
        Dim SW As System.IO.StreamWriter = myprocess1.StandardInput
        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"
        ' SR.Close()
        'End If
    End Sub
Posted 2-Apr-13 8:59am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
iismoove at 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 at 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)

  Print Answers RSS
0 Abhinav S 205
1 CHill60 180
2 KrunalRohit 169
3 Palash Mondal_ 140
0 OriginalGriff 3,877
1 KrunalRohit 2,496
2 CPallini 2,240
3 Maciej Los 2,205
4 ppolymorphe 1,750

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100