Public Function WaitForAppToQuit (sEXEName As String, sFQEXEName As String, _ lWaitSeconds As Long) As Integer ' Suspend execution until app with specified EXE quits ' or until lWaitSeconds seconds has passed ' ' If sFQEXEName is not empty, use it. Otherwise, use sEXEName. ' Returns 0 on success ' Returns 1 if no process with the specified EXE ' Returns 2 if both sFQName and sName are empty ' Returns 3 if error getting process list ' Returns 4 if cannot get handle to existing process ' Otherwise returns the return value of WaitForSingleObject Dim lret As Long Dim hProcessID As Long Dim hProcess As Long Dim cMatches As Long Dim sEXE As String hProcessID = GetWinNTProcessID(sFQEXEName, sEXEName, cMatches) If hProcessID <= 0 Then ' Error--translate to error code for this function If hProcessID = 0 Then WaitForAppToQuit = 1 ' no such process ElseIf hProcessID = -1 Then WaitForAppToQuit = 2 ' no EXE specified ElseIf hProcessID = -2 Then WaitForAppToQuit = 3 ' error getting process list End If Exit Function End If ' Get handle from process ID hProcess = ProcHndFromProcIDSync(hProcessID) If hProcess = 0 Then WaitForAppToQuit = 4 ' error getting process handle Exit Function End If ' Wait WaitForAppToQuit = WaitForSingleObject(hProcess, 1000& * lWaitSeconds) CloseHandle hProcess End Function |