I have almost never used the API before. I am tring to close a self-extracting zip file. I call the syncshell function and then wait for it to finish unzipping. When it is done I want to close the dos shell and move to the next file. I recieved some code from a previous post. I am just not sure if I am using it correctly. I have also noticed that the open process function is returning 0 and the If statement is not running. I think this is because I am using synchronized access on a windows 98 workstaion. What should I use?
Here is the code I am using:
Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Public Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessID As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal dwMilliseconds As Long) As Long
'---------------- global constants -------
Global Const INFINITE = &HFFFFFFFF
Global Const SYNCHRONIZED = &H100000
Public Sub SyncShell(ByVal sql As String, _
Optional ByVal vbwindowmode As VbAppWinStyle = vbMinimizedFocus)
Dim pid As Long
Dim phnd As Long
pid = Shell(sql)
If pid <> 0 Then
phnd = OpenProcess(SYNCHRONIZED, 0, pid)
If phnd <> 0 Then
DoEvents
WaitForSingleObject phnd, INFINITE
CloseHandle phnd
DoEvents
End If
End If
End Sub
Here is the code I am using:
Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Public Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessID As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal dwMilliseconds As Long) As Long
'---------------- global constants -------
Global Const INFINITE = &HFFFFFFFF
Global Const SYNCHRONIZED = &H100000
Public Sub SyncShell(ByVal sql As String, _
Optional ByVal vbwindowmode As VbAppWinStyle = vbMinimizedFocus)
Dim pid As Long
Dim phnd As Long
pid = Shell(sql)
If pid <> 0 Then
phnd = OpenProcess(SYNCHRONIZED, 0, pid)
If phnd <> 0 Then
DoEvents
WaitForSingleObject phnd, INFINITE
CloseHandle phnd
DoEvents
End If
End If
End Sub