Search code examples
c#processstart-process

How to hide the CMD console from this code?


How to hide the console from within this code? Currently the cmd console is shown everytime I run this code.

protected override void OnStart(string[] args)
{            
    String applicationName = "cmd.exe";
    // launch the application
    ApplicationLoader.PROCESS_INFORMATION procInfo;
    ApplicationLoader.StartProcessAndBypassUAC(applicationName, out procInfo);

}

How can I execute a *.bat file from here? Can I simply can substitute the "cmd.exe" with "xxx.bat"?


Solution

  • Add a System Reference to the code;

    using System Diagnostics;
    

    Then use this code to Hide the CMD Window and run.

    Process cmd = new Process();
    cmd.StartInfo.FileName = "cmd.exe";
    cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    cmd.StartInfo.Arguments = "Your arguments";
    cmd.Start();