Results 1 to 8 of 8

Thread: Hide Process By Process ID

  1. #1
    Lively Member
    Join Date
    Feb 12
    Posts
    71

    Hide Process By Process ID

    Hello

    However I am able to Get Process ID (PID) of an EXE i am executing with my application. I want to Hide that EXE Process with the help of it's Process ID.

    I am using following command to Get Process ID.

    Code:
    Dim oShell, oExec, oPid
        Set oShell = CreateObject("Wscript.Shell")
        DoEvents
        Set oExec = oShell.Exec("Exe path here")
        oPid = oExec.ProcessID
    As the above code doesn't support Window HIDE parameter. I donot want to use
    oShell.Run

    Is there any option or API to hide External Application's Window with the help of it Process ID?

    Thanks with Regards,

  2. #2
    PowerPoster
    Join Date
    Feb 06
    Posts
    8,577

    Re: Hide Process By Process ID

    It isn't clear why you are using WScript's Shell object for this, since there are better ways to do it using a fully compiled language such as VB6. Are you planning to read/write the child process' StdIO streams or what?

    That DoEvents call seems quite pointless, why is it there?

    VB's own lighter, faster, intrinsic Shell() function offers an optional windowstyle argument that can be used to "hide" the child's window. WScript's Shell object's Exec() method doesn't offer this, though the Run() method which is probably what you really want anyway does, in much the same way as VB's Shell() function.


    All of this is covered in the MSDN Library CD documentation that comes with every legit copy of VB6.

  3. #3
    Lively Member
    Join Date
    Feb 12
    Posts
    71

    Re: Hide Process By Process ID

    Hello @dilettante,
    Thanks for the reply, Yes you are right. I want to get the StdOut of the command Prompt(Hide).
    See the code below :

    Code:
    Function ejecutar_Dos(Comando As String) As String
        Dim oShell, oExec, oPid
        Set oShell = CreateObject("Wscript.Shell")
        DoEvents
        Set oExec = oShell.Exec("%comspec% /c " & Comando)
        oPid = oExec.ProcessID
        ejecutar_Dos = oExec.StdOut.ReadAll()
        DoEvents
        Me.SetFocus
    End Function
    Regards,

  4. #4
    PowerPoster
    Join Date
    Feb 06
    Posts
    8,577

    Re: Hide Process By Process ID

    Ok, well to do that cleanly you'll have to use API calls beginning with CreateProcess().

    Exec()'s methods all block, making it problematic from a Windows program. It was designed for use in Console script (CScript). This is also why you're seeing that "extra" Console window that a CScript script would not produce, and why there isn't any provision to suppress it.

    I use ShellPipe "Shell with I/O Redirection" control for this kind of thing. It offers a lot more flexibility as well as async operation (albeit Timer-driven polling based).

  5. #5
    Lively Member
    Join Date
    Feb 12
    Posts
    71

    Re: Hide Process By Process ID

    Hello dilettante,
    Thanks for reply again,
    I'v tried the 'ShellPipe' Usercontrol from your link, But after doing:
    Code:
    Select Case ShellPipe.Run(Environ$("COMSPEC"))
    It's showing 'Idle' and then noting happen after 'Make request'.

    Regards,
    Last edited by green.pitch; Aug 20th, 2012 at 01:45 AM.

  6. #6
    PowerPoster
    Join Date
    Feb 06
    Posts
    8,577

    Re: Hide Process By Process ID

    Why on earth are you starting an instance of the command shell as your child process? If you have a console program that you want to run and (interact with via its StdIO streams) then that's the program you should run.

    If you are really doing something more unusual, like trying to use command shell commands instead of running a console program then sure, you'd run the command shell. But then to invoke commands you need to write the comand line to the StdIn stream. This is why ShellPipe has a SendLine() method. Alternatively you can supply one on the command line as you were doing with WshShell.Exec() calls.

    I assume you're aware of the difference between a command like dir and a program like ping. ShellPipe can run ping directly but to do a dir you have to start cmd.exe and send it the dir command line.

    Normally you can skip using COMSPEC, it was created for use during the transition from Win9x to NT-based Windows. You only need it if you still support antique computers.

  7. #7
    Lively Member
    Join Date
    Feb 12
    Posts
    71

    Re: Hide Process By Process ID

    Hello, I am doing everything usual. I just want to execute a MsDOS command and want to get its output after it's completion But i don't want to display cmd.exe..

    Thank you !

  8. #8
    PowerPoster
    Join Date
    Feb 06
    Posts
    8,577

    Re: Hide Process By Process ID

    You seem to be quite lost.

    There are no "MsDOS commands" anymore, "DOS" died with Win9x. Perhaps this is lay speech for "console commands" instead?

    The command shell in modern Windows versions, which are all NT-based, is cmd.exe. If you are still using Win9x you'd use the similar command.com of course. From within these shell programs you can execute console programs such as ping.exe or you can execute internal commands built into these shells such as dir.


    Without writing the whole thing for you I'm not sure how much more I can help.

    The attached example does more or less what you seem to be asking for, but it runs the command shell as a child process and "talks to" the StdIO streams via two Textboxes as an interactive demo. For your purposes you wuldn't use these and instead would just write your commands via SendData and/or SendLine and get results via DataArrival and GetData and/or GetLine.

    Beyond this you might need to find a programmer to assist you.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •