You could use the WaitForSingleObjectEx() API after getting the Process Handle from the returned ProcessID using the OpenProcess() API, i.e.
In a Module:
VB Code:
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObjectEx Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long, ByVal bAlertable As Long) As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Function RunEXE(ByVal Filename As String) As Single
Dim lProcessID As Long
Dim lProcessHandle As Long
Dim tTimer As Single
Dim bStillRunning As Boolean
tTimer = Timer
lProcessID = Shell(Filename, vbNormalFocus)
lProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, lProcessID)
Do
bStillRunning = WaitForSingleObjectEx(lProcessHandle, 10, 0)
DoEvents
Loop While bStillRunning
Call CloseHandle(lProcessHandle)
RunEXE = (Timer - tTimer)
End Function
Example:
VB Code:
Private Sub Command1_Click()
MsgBox "Notepad was closed after running for: " & Round(RunEXE("Notepad.exe"), 2) & " seconds.", vbInformation + vbOKOnly, "Time Running:"
End Sub