2013-07-31 210 views
1

我試圖在單擊事件中運行以下代碼。但是,因爲它在cmd shell中執行命令,我不知道它爲什麼不運行。我可以做的是通過註釋參數打開cmd.exe作爲管理員。以及將這些參數粘貼到.bat文件中,然後從process.start運行。從vb.net運行cmd命令問題

但是,爲什麼我不能運行shell的參數?我寧願將這些參數放在.bat文件中。

Dim process As New System.Diagnostics.Process() 
     Dim startInfo As New System.Diagnostics.ProcessStartInfo() 
     ' startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden 

     startInfo.FileName = "cmd.exe" 
     If System.Environment.OSVersion.Version.Major >= 6 Then ' Windows Vista or higher 
      startInfo.Verb = "runas" 
     Else 
      ' No need to prompt to run as admin 
     End If 
     startInfo.Arguments = "/C bcdedit /set {current} safeboot network" 
     process.StartInfo = startInfo 
     process.Start() 
+0

嘗試使用'cmd.exe'的完整文件路徑。 – Sheridan

+0

那麼startInfo.FileName =「cmd.exe/C bcdedit/set {current} safeboot network」? –

+0

嘗試更改/ C in/K以查看是否有任何錯誤消息 – Steve

回答

0

想通了。我不得不將bcdedit.exe複製到我的項目中。我以爲調用cmd.exe會去bcdedit.exe所在的位置。