Run CMD Silently

前端 未结 1 350
死守一世寂寞
死守一世寂寞 2021-01-14 07:05

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.Start         


        
相关标签:
1条回答
  • 2021-01-14 08:06

    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

    0 讨论(0)
提交回复
热议问题