Just try to open the process. If it opens, it exists, otherwise, terminated.
___
[tt]
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Sub Form_Load()
Dim ProcessId As Long
ProcessId = Shell("notepad.exe", vbNormalFocus)
'....
MsgBox IsProcessRunning(ProcessId)
End
End Sub
Function IsProcessRunning(pid As Long) As Boolean
Dim hProcess As Long
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
CloseHandle hProcess
IsProcessRunning = hProcess
End Function[/tt]
___
See also thread222-859655 for a synchronous solution.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.