Guest User

Untitled

a guest
Jul 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. Private Function ShellAndWait(ByVal program_name As String, ByVal window_style As VbAppWinStyle) As Boolean
  2. Dim process_id As Long
  3. Dim process_handle As Long
  4. Dim exitCode As Long
  5.  
  6. ' Start the program.
  7. On Error GoTo ShellError
  8. process_id = Shell(program_name, window_style)
  9. On Error GoTo 0
  10.  
  11. ' Hide.
  12.  
  13. DoEvents
  14.  
  15. ' Wait for the program to finish.
  16. ' Get the process handle.
  17. process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
  18. If process_handle <> 0 Then
  19. WaitForSingleObject process_handle, INFINITE
  20.  
  21. GetExitCodeProcess process_handle, exitCode
  22. CloseHandle process_handle
  23. End If
  24.  
  25. ' Reappear.
  26. MsgBox program_name & " exit code: " & exitCode, vbOKOnly
  27. ShellAndWait = (exitCode = 0)
  28. Exit Function
  29.  
  30. ShellError:
  31. MsgBox "Error starting task " & Err.Description, vbOKOnly Or vbExclamation, "Error"
  32.  
  33. ShellAndWait = False
  34. End Function
Add Comment
Please, Sign In to add comment