Run CMD Silently

こ雲淡風輕ζ 提交于 2019-12-01 07:19:31

问题


I'm trying to run CMD silently, but each time I get an error. Could someone please tell me where I'm going wrong?

Dim myProcess As Process 
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden 
myProcess.StartInfo.CreateNoWindow = True 
myProcess.StartInfo.FileName = ("cmd.exe" & CmdStr) 
myProcess.Start() 

CmdStr is already a string to do certain things that I want in the application.


回答1:


I suppose your cmdStr is a string with parameters for CMD.
If so you need to use the Arguments property of StartInfo.
You get a Null Exception on the myProcess variable because it is never instatiated with new. You could create a ProcessStartInfo var to use with the static Process.Start method and set the UseShellExecute to False

Dim startInfo As New ProcessStartInfo("CMD.EXE")
startInfo.WindowStyle = ProcessWindowStyle.Hidden     
startInfo.CreateNoWindow = True 
startInfo.UseShellExecute = False
startInfo.Arguments = CmdStr
Process.Start(startInfo)  

or edit your code to add

myProcess = new Process() 

before using the var myProcess



来源:https://stackoverflow.com/questions/12477776/run-cmd-silently

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!