Is there a way to hide the console window when executing a console application?
I am currently using a Windows Forms application to start a console process but I don't want the console window to be displayed while the task is running.
Is there a way to hide the console window when executing a console application?
I am currently using a Windows Forms application to start a console process but I don't want the console window to be displayed while the task is running.
if you are using the ProcessStartInfo class you can set the window style to hidden.
System.Diagnostics.ProcessStartInfo start =
new System.Diagnostics.ProcessStartInfo();
start.FileName = dir + @"\Myprocesstostart.exe";
start.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
I know I'm not answering exactly what you want, but I am wondering if you're asking the right question.
Why don't you use either:
Those sound like better options if all you want is to run a process.
You can use the FreeConsole API to detach the console from the process :
[DllImport("kernel32.dll")]
static extern bool FreeConsole();
(of course this is applicable only if you have access to the console application's source code)
If you're creating a program that doesn't require user input you could always just create it as a service. A service won't show any kind of UI.
If you wrote the console application you can make it hidden by default.
Create a new console app then then change the "Output Type" type to "Windows Application" (done in the project properties)
Simple answer is that: Go to your console app's properties(project's properties).In the "Application" tab, just change the "Output type" to "Windows Application". That's all.