hmmm . . . OK, using Shell and the OpenProcess API are still your best bets to get the application handle rather than using the FindWindow API, but actually, you may not even need the OpenProcess API unless you want to be able to close the other apps from your controlling applitication.
As for waiting for the other app to close, you could use the WaitForSingleObject API, but that would lock up your controlling appplication until the user closed the app they opened (unless VB could handle multiple threads, but it can't do that . . . yet). Of course you could write a C++ DLL that would use multithreading and simply signal you VB app when the other apps had closed . . . just a thought, but I think that this option would be the most responsive.
Using pure VB, I'd do this . . . Use the Shell command to lauch your applications. Keep the process ID that is returned from the Shell command. Then, using a timer control, periodically enumerate through the process list to see what processes are currently running (See code below). If you process handle is not in the enumerated process list, then the app has been closed.
Here is the code to get a list of just the running process IDs . . .
Code:
Private Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Code:
private Sub GetProcessHandles
Code:
Dim lngProcessID() As Long
Dim lngCB As Long
Dim lngCBNeeded As Long
Dim lngRetCode As Long
Code:
'** Get the current list of running Processes IDs
'******************************************************************************
Code:
lngCB = 8
lngCBNeeded = 96
Do While lngCB <= lngCBNeeded
lngCB = lngCB * 2
ReDim lngProcessIDs(lngCB / 4) As Long
lngRetCode = EnumProcesses(lngProcessIDs(1), lngCB, lngCBNeeded)
If lngRetCode = 0 Then
MsgBox Err.LastDllError
Exit Do
End If
Loop
Code:
'******************************************************************************
==================================================================================== - Jeff Marler B-)