Results 1 to 2 of 2

Thread: Find if Process is still running using processID

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2002
    Location
    The Netherlands
    Posts
    31

    Find if Process is still running using processID

    Hello, I want to solve the next situation.

    I start multiple executables using the Shell command. This function returns the processID. After a while I want to check if the processID is still in use by me. Thus: check if processID exists, check if name of process is the one I used to start it up.

    Thanks for your solution!

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299
    If you have the Process id from Shell you'll need to get the handle from it using OpenProcess
    Code:
    Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Then with that you can loop around till it finishs with WaitForSingleObject
    Code:
    Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Then when its done close the handle with CloseHandle

    Code:
    Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

    For example (this may not run as i'm just going from memory)
    Code:
    processID = Shell("MyProg.exe",vbNormalFocus)
    If processID <> 0 then 
        procHandle = OpenProcess(Process_Query_Information,0,processID)
        if procHandle <> 0 then
            rc = WaitForSingleObject(procHandle,100)
            do while rc <> 0
                rc = WaitForSingleObject(procHandle,100)
                DoEvents
            loop
            CloseHandle(procHandle)
        end if
        msgbox "process has ended"
    end if

    That will let you know if the process is running. Well actually that will more wait for a process to finish then let you know.
    you could change that to set a boolean to true before the do loop called isRunning and then set it to false when its finished. Then you could just query your boolean.

Posting Permissions

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



Click Here to Expand Forum to Full Width