Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. Function ShellWait(CommandLine As String, _
  2. TimeOut As Long, _
  3. WindowState As VbAppWinStyle) As Boolean
  4.  
  5. Dim ProcessID As Long
  6. Dim hProcess As Long
  7.  
  8. ProcessID = Shell(CommandLine,WindowState)
  9. If ProcessID <> 0 Then
  10. 'non-zero (True) so Shell worked
  11. ' Get a process handle for the PID (Wait takes a handle)
  12. hProcess = OpenProcess(SYNCHRONIZE, False, ProcessID)
  13. If hProcess <> 0 Then
  14. ' Got process handle
  15. ' Wait until process finishes before going on
  16. If WaitForSingleObject(hProcess, TimeOut) = WAIT_OBJECT_0 Then
  17. ShellWait = True
  18. Else
  19. ShellWait = False
  20. End If
  21. Else
  22. 'Failed to get process handle.
  23. 'Perhaps the process terminated very quickly
  24. 'or it might not really have executed at all even though Windows
  25. ' started a process.
  26. ShellWait = False
  27. End If
  28. Else
  29. ' PID zero (False) so Shell failed
  30. ShellWait = False
  31. End If
  32. End Function
  33.  
  34.  
  35. Call to function:
  36.  
  37. If ShellWait("rsync.exe -adi {remote_src_dir} {local_dest_dir}") then
  38. MsgBox "Fetched List"
  39. Else
  40. MsgBox "Failure :-("
  41. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement