tags:

views:

1469

answers:

4

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();
}
+2  A: 

Try this:

myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
galets
+1  A: 

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.

Paul Alexander
+4  A: 

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.

Mun
+2  A: 

@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;
codefox