0

is msdn wrong when it says that to use ProcessWindowStyle.Hidden the ProcessStartInfo.UseShellExecute property must be false ?

https://msdn.microsoft.com/en-us/library/system.diagnostics.processwindowstyle(v=vs.110).aspx

enter image description here

Firstly it's not ProcessStartInfo.UseShellExecute, it's an instance of ProcessStartInfo dot UseShellExecute but that aside.

Secondly, and most importantly. I find the opposite is true

If I create e.g. a winforms application, with this code Then a cmd window appears

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.UseShellExecute = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);

If however I do

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.UseShellExecute = true; //default
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);

Then the cmd window doesn't appear.

So it seems that ProcessWindowStyle.Hidden requires UseShellExecute to be true/default. Not false. Exactly the opposite of what msdn says.

Is msdn completely wrong in its documentation, or am I misunderstanding it?

Also, this answer here .NET - WindowStyle = hidden vs. CreateNoWindow = true? backs up what i've found that CreateNoWindow is for when UseShellExecute = false, and psi.WindowStyle=ProcessWindowStyle.Hidden is for when UseShellExecute=true(default). Msdn points that out for CreateNoWindow but msdn seems to be get it wrong with ProcessWindowStyle.Hidden.

Community
  • 1
  • 1
barlop
  • 12,887
  • 8
  • 80
  • 109
  • related- http://stackoverflow.com/questions/5094003/net-windowstyle-hidden-vs-createnowindow-true – barlop Apr 25 '16 at 06:31
  • Oddly, that note only appears in the 3.5 and later documentation. Also, not sure what point you're trying to make in your "Firstly ..." sentence. – Damien_The_Unbeliever Apr 25 '16 at 06:48
  • The MSDN article is indeed wrong. Might have been inspired by ProcessWindowStyle.Hidden so very rarely working as intended, a well-written program often ignores it. You can file doc bugs at connect.microsoft.com – Hans Passant Apr 25 '16 at 07:34
  • @Damien_The_Unbeliever my firstly point wasn't of great significance, but was my first point technically correct too? if a property is instance not static, isn't it wrong to describe it as if it were static? – barlop Apr 25 '16 at 11:28
  • @barlop - I'm not aware of anywhere in the documentation where they'll go out of their way to go "oh, but this is an instance method, so you'll need to obtain an instance of the class from somewhere". It's just a reference to the names of the class and property. If you want to *use* those, further research is almost always required. I think the documentation is consistent in this matter. – Damien_The_Unbeliever Apr 25 '16 at 11:58
  • @HansPassant what do you mean a well written program ignores `ProcessWindowStyle.Hidden` do you mean it has code in it to prevent it from operating.. or do you mean normally it won't work on a program(and will only function if a program has some badly written extra stuff), or do you mean a well written program will not use that facility to invoke a program in a hidden window, it'd use another facility(eg win api)?. To put it another way.. can you give an example of well written code vs badly written code with regard to this? – barlop Apr 25 '16 at 12:06
  • submitted bug report https://connect.microsoft.com/VisualStudio/feedback/details/2632284 – barlop Apr 26 '16 at 14:34
  • @HansPassant you can post that as an answer and i'll accept it – barlop Apr 30 '16 at 16:43

0 Answers0