Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function ShellWait(CommandLine As String, _
- TimeOut As Long, _
- WindowState As VbAppWinStyle) As Boolean
- Dim ProcessID As Long
- Dim hProcess As Long
- ProcessID = Shell(CommandLine,WindowState)
- If ProcessID <> 0 Then
- 'non-zero (True) so Shell worked
- ' Get a process handle for the PID (Wait takes a handle)
- hProcess = OpenProcess(SYNCHRONIZE, False, ProcessID)
- If hProcess <> 0 Then
- ' Got process handle
- ' Wait until process finishes before going on
- If WaitForSingleObject(hProcess, TimeOut) = WAIT_OBJECT_0 Then
- ShellWait = True
- Else
- ShellWait = False
- End If
- Else
- 'Failed to get process handle.
- 'Perhaps the process terminated very quickly
- 'or it might not really have executed at all even though Windows
- ' started a process.
- ShellWait = False
- End If
- Else
- ' PID zero (False) so Shell failed
- ShellWait = False
- End If
- End Function
- Call to function:
- If ShellWait("rsync.exe -adi {remote_src_dir} {local_dest_dir}") then
- MsgBox "Fetched List"
- Else
- MsgBox "Failure :-("
- End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement