Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Command prompt (cmd.exe) as a hidden process

Command prompt (cmd.exe) as a hidden process

Scheduled Pinned Locked Moved Visual Basic
csharpdesigntutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Martin Smith
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • M Martin Smith

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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 being False. 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" while UseShellExecute is False! 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

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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 being False. 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" while UseShellExecute is False! 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

        M Offline
        M Offline
        Martin Smith
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups