Command prompt (cmd.exe) as a hidden process
-
Hi all, I am writing a VB.Net application that has a Command Prompt, which is running as a hidden process and I am redirecting the standard input/output from this process to my own user interface. Everything seems to be working fine for regular DOS commands, for example; If I type "DIR" into my user-interface it displays exactly the same as if I'd typed DIR in to a command prompt window -- no problems there.... If I enter the name of an executable that is a windows based application, for example notepad.exe, then nothing seems to happen. If I then close my application the program I tried to start (i.e. Notepad) magically appears. Having delved a bit deeper into this, I notice that after executing the notepad.exe command in my user interface, task manager is showing a "notepad.exe" process running but its not visible. I tried executing the dos command "start notepad.exe", and hey presto - the Notepad application starts up and is immediately visible. Does anybody have any ideas as to why my hidden command prompt process is not making windows based applications immediately visible (unless they are proceeded by the "start" command)?? Thanks, Martin
-
Hi all, I am writing a VB.Net application that has a Command Prompt, which is running as a hidden process and I am redirecting the standard input/output from this process to my own user interface. Everything seems to be working fine for regular DOS commands, for example; If I type "DIR" into my user-interface it displays exactly the same as if I'd typed DIR in to a command prompt window -- no problems there.... If I enter the name of an executable that is a windows based application, for example notepad.exe, then nothing seems to happen. If I then close my application the program I tried to start (i.e. Notepad) magically appears. Having delved a bit deeper into this, I notice that after executing the notepad.exe command in my user interface, task manager is showing a "notepad.exe" process running but its not visible. I tried executing the dos command "start notepad.exe", and hey presto - the Notepad application starts up and is immediately visible. Does anybody have any ideas as to why my hidden command prompt process is not making windows based applications immediately visible (unless they are proceeded by the "start" command)?? Thanks, Martin
I can duplicate your problem, but I can't figure out why it's doing what it is. I think it has something to do with
UseShellExecute
, but you don't have much of a choice there considering you can't redirect the Streams without it beingFalse
. The reason I say this is because you start the CMD process WITHOUT the shell. Any process that's launched from that CMD will ALSO not be launched from the Shell. The START executable gets around that by creating a new instance of the Shell and launching your command line through that (I THINK!). Funny thing is that you can't launch your hidden, or otherwise, CMD process with "START CMD.EXE" whileUseShellExecute
isFalse
! You also can't tell your successfully launched hidden CMD process to launch another CMD process using START ("CMD.EXE /K START CMD.EXE") without a Win32 error stopping you. Sorry, it looks like there is no way around this that I can think of...Dave Kreskowiak Microsoft MVP - Visual Basic
-
I can duplicate your problem, but I can't figure out why it's doing what it is. I think it has something to do with
UseShellExecute
, but you don't have much of a choice there considering you can't redirect the Streams without it beingFalse
. The reason I say this is because you start the CMD process WITHOUT the shell. Any process that's launched from that CMD will ALSO not be launched from the Shell. The START executable gets around that by creating a new instance of the Shell and launching your command line through that (I THINK!). Funny thing is that you can't launch your hidden, or otherwise, CMD process with "START CMD.EXE" whileUseShellExecute
isFalse
! You also can't tell your successfully launched hidden CMD process to launch another CMD process using START ("CMD.EXE /K START CMD.EXE") without a Win32 error stopping you. Sorry, it looks like there is no way around this that I can think of...Dave Kreskowiak Microsoft MVP - Visual Basic
Thanks a lot for having a look into my problem Dave, You have provided a brilliant analysis, and I guess its a limitation I am going to have to live with.... Best regards, Martin