Re: task list
From: Tom Esh (tjeshGibberish_at_earthlink.net)
Date: 05/04/04
- Next message: Bernie: "Re: Where in the registry..."
- Previous message: Karl E. Peterson: "Re: task list"
- In reply to: ted Bogucki: "task list"
- Next in thread: Björn Holmgren: "Re: task list"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 04 May 2004 14:44:25 -0400
On Tue, 4 May 2004 14:01:47 -0400, "ted Bogucki" <ted@sma-promail.com>
wrote:
>Does anyone know how to get the list of tasks running.
>I have written a program that starts up other programs. I want to be
>able to check to see it the processed that I created is still associated
>with the program that my main program started or if the program aborted for
>any reason.
You can enumerate the processes with:
CreateToolhelp32Snapshot
Process32First
Process32Next
However if you're only interested in processes that your app has
started, it may make more sense to grab the PID or a process handle
when you launch them. This also has the advantage of identifying only
those instances you've launched (as opposed to any others the user may
have started). VB's Shell function returns the PID, which you can
subsequently use with OpenProcess to obtain a handle. Alternatively
you could use CreateProcess to launch them, which provides a proc
handle. Once you have the proc handle, you can check the state of the
process with GetExitCodeProcess.
Ex (air-code, sans declares):
Dim m_PIDs As Collection 'PID stash
Public Sub LaunchApp(sPath As String)
Dim PID As Long
PID = Shell(sPath, vbNormalFocus)
If PID <> 0 Then
m_PIDs.Add PID, sPath
End If
End Sub
Public Function IsProcRunning(sPath As String) As Boolean
Dim PID As Long
Dim hProc As Long
Dim ExitCode As Long
PID = m_PIDs.Item(sPath)
hProc = OpenProcess(PROCESS_QUERY_INFORMATION Or SYNCHRONIZE, _
0, PID)
If hProc <> 0 Then
GetExitCodeProcess hProc, ExitCode
If ExitCode = STILL_ACTIVE Then
IsProcRunning = True
End If
CloseHandle hProc
End If
End Function
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
- Next message: Bernie: "Re: Where in the registry..."
- Previous message: Karl E. Peterson: "Re: task list"
- In reply to: ted Bogucki: "task list"
- Next in thread: Björn Holmgren: "Re: task list"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|