VB Code:
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const SYNCHRONIZE = &H100000 ' Remove the spaces between the digits
Private Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
Private Const STATUS_TIMEOUT = &H102
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public sub SyncShell(PathName, Optional WindowStyle As VbAppWinStyle = vbMinimizedFocus)
'Yonatan, modified by Nucleus
Dim dwProcessID As Long, hProcess As Long
dwProcessID = Shell(PathName, WindowStyle)
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, dwProcessID)
If hProcess Then
Do
DoEvents
Loop While WaitForSingleObject(hProcess, 0) = STATUS_TIMEOUT
end if
End Sub