I am trying to create process on a remote machine using using System.Diagnostics.Process class.
I am able to create a process. But the problem is, creating a service is take a long time and console window is displayed.
Another annoying thing is the console window is displayed on top of my windows form and i cant do any other operations on that form.
I have set all properties like CreateNoWindow = true
,
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
but still it shows the console window. even i have redirected output and errors to seperate stream but no luck.
Is there any other way to hide the Console window? Please help me out .
Here is the part of my code i used to execute sc command.
Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.FileName = "sc";
proc.StartInfo.Arguments = string.Format(@"\\SYS25 create MySvc binPath= C:\mysvc.exe");
proc.StartInfo.RedirectStandardError = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
This doesn't show the window:
I had a similar issue when attempting to start a process without showing the console window. I tested with several different combinations of property values until I found one that exhibited the behavior I wanted.
Here is a page detailing why the
UseShellExecute
property must be set to false.http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.createnowindow.aspx
Under Remarks section on page:
I've had bad luck with this answer, with the process (Wix light.exe) essentially going out to lunch and not coming home in time for dinner. However, the following worked well for me:
This should work, try;
Add a System Reference.
Then use this code to run your command in a hiden CMD Window.