Search code examples
c#console-application

How to run a C# console application with the console hidden


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.


Solution

  • If you are using the ProcessStartInfo class you can set the window style to hidden - in the case of console (not GUI) applications, you have to set CreateNoWindow to true:

    System.Diagnostics.ProcessStartInfo start =
          new System.Diagnostics.ProcessStartInfo();
    start.FileName = dir + @"\Myprocesstostart.exe";
    start.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //Hides GUI
    start.CreateNoWindow = true; //Hides console