console application - C# I can't get CreateNoWindow to work - not even the msdn.com example -


i have looked here

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

and understand

a) not every program respects createnowindow request and

b) requires useshellexecute=false (default true).

c) meant indicate whether window created. (it won't ever hide parent window). it's speaking of whether window created child process. (msdn says 'new window')

d) createnowindow defaults false.

i running cmd, though clicking play in visual studio illustrates same behaviour.

i set createnowindow false i'd have thought it'd create new window child process.

but not.

task manager shows second instance of cmd.exe there's still 1 window can see. below paste 1 window. has loaded child cmd.exe in parent window (the 1 cmd window)

if set createnowindow true or false, seems make no difference.

so i'm not getting example @ msdn link work.

c:\crp>type aaa.csc using system.diagnostics;  class blah{    public static void main(string[] args) {           process p = new process();           processstartinfo psi = new processstartinfo();           psi.useshellexecute=false;            psi.filename="cmd.exe";           psi.createnowindow=false;           p.startinfo=psi;           p.start();    } } c:\crp>csc aaa.csc microsoft (r) visual c# compiler version 4.0.30319.34209 microsoft (r) .net framework 4.5 copyright (c) microsoft corporation. rights reserved.   c:\crp>aaa.exe  c:\crp>microsoft windows [version 6.1.7601] copyright (c) 2009 microsoft corporation.  rights reserved.  c:\crp> 

update

it seems work. if open cmd prompt , run exe, in 1 case starts cmd.exe within parent. in other case starts cmd.exe without window. behaviour within visual studio seems odd though, see comment ephraim's answer. in question while within visual studio, i'd tried project set being console application, , there cmd prompt window @ least flick up. behaviour simpler non console application e.g. winforms application.

try out using visual studio , define pull file path cmd.exe

public static void main(string[] args) {     try      {       processstartinfo psi = new processstartinfo();       psi.filename = "c:\\windows\\system32\\cmd.exe"; // full path       psi.createnowindow = true;        psi.useshellexecute = false;       process childprocess = process.start(psi); // child process       // code assumes process starting terminate itself.        // given is started without window cannot terminate        // on desktop, must terminate or can programmatically       // application using kill method.     }     catch(exception ex)     {         console.writeline(e.message);     } } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -