Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET - WindowStyle = hidden vs. CreateNoWindow = true?

When I start a new process, what difference does it make if I use the

WindowStyle = Hidden 

or the

CreateNoWindow = true 

property of the ProcessStartInfo class?

like image 686
Gabor Avatar asked Feb 23 '11 16:02

Gabor


1 Answers

As Hans said, WindowStyle is a recommendation passed to the process, the application can choose to ignore it.

CreateNoWindow controls how the console works for the child process, but it doesn't work alone.

CreateNoWindow works in conjunction with UseShellExecute as follows:

To run the process without any window:

ProcessStartInfo info = new ProcessStartInfo(fileName, arg);  info.CreateNoWindow = true;  info.UseShellExecute = false; Process processChild = Process.Start(info);  

To run the child process in its own window (new console)

ProcessStartInfo info = new ProcessStartInfo(fileName, arg);  info.UseShellExecute = true; // which is the default value. Process processChild = Process.Start(info); // separate window 

To run the child process in the parent's console window

ProcessStartInfo info = new ProcessStartInfo(fileName, arg);  info.UseShellExecute = false; // causes consoles to share window  Process processChild = Process.Start(info);  
like image 55
Liz Avatar answered Sep 24 '22 08:09

Liz