Click here to Skip to main content
13,199,296 members (75,264 online)
Rate this:
Please Sign up or sign in to 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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171020.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2017
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