VB6 Tracking A Process

This sample code illustrates the usage of Windows API to track a process ID belonging to a command prompt process whether or not is already terminated before proceeding to perform other task.

The command prompt process in this example is to perform a timeout for 10 seconds before auto-closing the window. When this happens, the command prompt process terminates by itself.

The VB6 program will pick up the signal and then will send out notification.

You need to use two kernel32 APIs namely..

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Check out the code here or download here or here (Planet Source Code).

Thanks to these reference sites which offers incomplete descriptions.