Need to execute command from within Windows form

  • Thread starter Thread starter Philip Colmer
  • Start date Start date
P

Philip Colmer

I need to run a command line tool from within a Windows form application
without the command window opening at all. I had found some code (below) but
the window is still opening.

Dim psi As New System.Diagnostics.ProcessStartInfo(strCmd,
strParams)
psi.RedirectStandardOutput = True
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
Dim listFiles As System.Diagnostics.Process
listFiles = System.Diagnostics.Process.Start(psi)
Dim myOutput As System.IO.StreamReader = listFiles.StandardOutput
listFiles.WaitForExit(20000)

Can anyone see what is wrong with this (i.e. why does the window open) or
does anyone have any suggestions for running command line stuff without the
black window appearing?

Thanks.

--Philip
 
Hi Philip,

Thanks for your post.

Base on my research, we can use CreateNoWindow property to get what you
want, sample code listed below:

psi.WindowStyle = ProcessWindowStyle.Hidden
psi.CreateNoWindow = True ¡®Just set CreateNoWindow = true, it works

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
"Jeffrey Tan[MSFT]" said:
Hi Philip,

Thanks for your post.

Base on my research, we can use CreateNoWindow property to get what you
want, sample code listed below:

psi.WindowStyle = ProcessWindowStyle.Hidden
psi.CreateNoWindow = True ¡®Just set CreateNoWindow = true, it works

Hope this helps

Thank you - that has solved it for me.

--Philip
 
It's my pleasure to help you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top