Launching process in C# Without Distracting Console Window

C#Process

C# Problem Overview


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;
    myProcess.Start();
    myProcess.WaitForExit();
}

C# Solutions


Solution 1 - C#

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
process.Start();

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.

Solution 2 - C#

@galets In your suggestion, the window is still created, only it begins minimized. This would work better for actually doing what acidzombie24 wanted:

myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

Solution 3 - C#

Try this:

myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;

Solution 4 - C#

I'll have to double check, but I believe you also need to set UseShellExecute = false. This also lets you capture the standard output/error streams.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser34537View Question on Stackoverflow
Solution 1 - C#MunView Answer on Stackoverflow
Solution 2 - C#codefoxView Answer on Stackoverflow
Solution 3 - C#galetsView Answer on Stackoverflow
Solution 4 - C#Paul AlexanderView Answer on Stackoverflow