Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Function ShellAndWait(ByVal program_name As String, ByVal window_style As VbAppWinStyle) As Boolean
- Dim process_id As Long
- Dim process_handle As Long
- Dim exitCode As Long
- ' Start the program.
- On Error GoTo ShellError
- process_id = Shell(program_name, window_style)
- On Error GoTo 0
- ' Hide.
- DoEvents
- ' Wait for the program to finish.
- ' Get the process handle.
- process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
- If process_handle <> 0 Then
- WaitForSingleObject process_handle, INFINITE
- GetExitCodeProcess process_handle, exitCode
- CloseHandle process_handle
- End If
- ' Reappear.
- MsgBox program_name & " exit code: " & exitCode, vbOKOnly
- ShellAndWait = (exitCode = 0)
- Exit Function
- ShellError:
- MsgBox "Error starting task " & Err.Description, vbOKOnly Or vbExclamation, "Error"
- ShellAndWait = False
- End Function
Add Comment
Please, Sign In to add comment