C# – Launching process in C# Without Distracting Console Window


I figure out how to launch a process. But my problem now is the console window (in this case 7z) pops up frontmost blocking my vision and removing my focus interrupting my sentence or w/e i am doing every few seconds. Its extremely annoying, how do i prevent that from happening. I thought CreateNoWindow solves that but it didnt.

NOTE: sometimes the console needs user input (replace file or not). So hiding it completely may be a problems a well.

This is my current code.

void doSomething(...)
    myProcess.StartInfo.FileName = ...;
    myProcess.StartInfo.Arguments = ...;
    myProcess.StartInfo.CreateNoWindow = true;

Best Answer

If I recall correctly, this worked for me

Process process = new Process();

// Stop the process from opening a new window
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

// Setup executable and parameters
process.StartInfo.FileName = @"c:\test.exe"
process.StartInfo.Arguments = "--test";

// Go

I've been using this from within a C# console application to launch another process, and it stops the application from launching it in a separate window, instead keeping everything in the same window.