System.Dianostics.Process.StartInfo.WindowMode = ...Hidden doesn't work
I am trying to get my program to execute a command line program, retrieve the results, process them and return them to a user from my program. However, it all works fine except that it doesn't hide the command window. It always appears, you can't see anything on it because it is redirected to my program and I have no idea how to stop it. I tried it with even just a simple batch file with nothing more than
Code:
@echo off
echo Hello World
in it and it still displays the window.
How can I prevent it from displaying the window?
Note: Using shell is not an option because shell doesn't redirect the output.
Code:
VB Code:
Dim Process As New Process 'Creates a new process
Dim StreamOut As IO.StreamReader 'Creates a stream reader to read the stream from the command
Dim Output As CommandOutput 'Holds the output from the command
'
'Creates the shutdown process
Process.StartInfo.FileName = "C:\Echo.bat"
Process.StartInfo.UseShellExecute = False
Process.StartInfo.RedirectStandardOutput = True
Process.StartInfo.RedirectStandardError = True
Process.StartInfo.RedirectStandardInput = True
Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden 'Hides the window from the user
Process.Start() 'Executes the process
StreamOut = Process.StandardOutput 'Retrieves the output from the process
Process.WaitForExit(2000) 'Waits for 20 seconds for the process to finish
Output = ProcessOutput(StreamOut.ReadToEnd) 'Converts the output from the command to CommandOutput
StreamOut.Close() 'Closes the stream reader