
Text1.SelText = "Task " & CStr(I) & " terminated, " _ If GetExitCodeProcess(Handles(I), ExitCode) 0 Then If WaitForSingleObject(Handles(I), 0) = WAIT_OBJECT_0 Then

If Handles(I) INVALID_HANDLE And Handles(I) DEAD_HANDLE Then Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) 'We'll run 3 copies of the command shell as an example. Private Declare Function WaitForSingleObject Lib "kernel32" ( _ Private Declare Function TerminateProcess Lib "kernel32" ( _ Private Declare Function OpenProcess Lib "kernel32" ( _ Private Declare Function GetExitCodeProcess Lib "kernel32" ( _ Private Declare Function CloseHandle Lib "kernel32" ( _ Private Const PROCESS_QUERY_INFORMATION = &H400& Paste this code into the Form: Option Explicit

Add a multiline TextBox Text1 and a Timer Timer1 (which is used to poll the children for completion).

To create the demo open a new VB6 Project with a Form. You could enter exit 1234 or somesuch to see this in action. This demo also reports back the exit code of each process that quits. See A Safer Alternative to TerminateProcess(). It is also written to kill any running children when it is terminated, and there are better alternatives to use in most cases. The example is coded to start and repeatedly restart 3 copies of the command shell (trivial sample child program). Ok, here is a super-stripped-down example of a program in VB6 to spawn and monitor programs. CreateProcess gives you the handle directly. The VB6 Shell() function returns a Process ID you can use to call OpenProcess with. You don't need to go spelunking for processes just to get a handle to child processes that you spawn. How To Enumerate Processes From VB 6 on Win 2003?.bat file but wait until its done running before moving on?
/i/1187356391.png)
