Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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.
 
code:
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 2-Apr-13 9:59am

1 solution

Rate this: bad
good
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
  Permalink  
Comments
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 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
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