问题描述
下午好,
我正在尝试运行Diskpart脚本,该脚本将为Windows 7映像部署创建新分区。我在切换驱动器和运行脚本时遇到了麻烦。我正在使用cmd.exe进程来运行diskpart。 cmd窗口以C:\开头,我需要将其更改为E:\,然后运行脚本。我没试过好几件事。我也有它将输出指向文本框。我在下面提供了我的功能,其中有一些我尝试过的注释。如果有人可以请求帮助,我将非常感激。
如果您还有其他需要,请告诉我。
代码:
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
推荐答案
CMD /C yourCommandLine
在你的情况下,你错过了CMD.EXE参数的/ C开关。你的命令行应该是:
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
这篇关于在VB.NET Process中运行Diskpart脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!