How can I hide a console window?

前端 未结 4 490
小蘑菇
小蘑菇 2020-12-09 17:35

Question: I have a console program that shouldn\'t be seen. (It resets IIS and deletes temp files.)

Right now I can manage to hide the window right after start like

4条回答
  •  北海茫月
    2020-12-09 18:17

    If I understand your question, just create the console process manually and hide the console window:

    Process process = new Process();
    process.StartInfo.FileName = "Bogus.exe";
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.CreateNoWindow = true;
    

    I do this for an WPF app which executes a console app (in a background worker) and redirects standard output so you can display the result in a window if needed. Works a treat so let me know if you need to see more code (worker code, redirection, argument passing, etc.)

提交回复
热议问题