I'm trying to create my own shellexecute program named shell4OD and am
having problems with handles. Here is my code ...
=====
Private Declare Function ShellExecute Lib _
"shell32.dl l" Alias "ShellExecu teA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As _
String, ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public function Shell4OD( byVal cmd as string, byVal parameters as
string, byVal Dir as string, byVal showHide as integer) As Boolean
Dim procHandle As Long, shellHnd As Long, taskID As Long
' hmmm shellHnd = ???? <=== here is my problem
taskID = ShellExecute( shellHnd, _
vbNull, cmd, parameters, Dir, showHide)
' get the process handle
procHandle = OpenProcess(&H1 00000, True, taskID)
Shell4OD = WaitForProcess( procHandle)
' close the handle
CloseHandle procHandle
end function
' Wait for a number of milliseconds, and return the running status
' of a process. If argument is omitted, wait untill the process
' terminates.
Function WaitForProcess( taskId As Long, Optional msecs As Long = -1) _
As Boolean
Dim procHandle As Long
' get the process handle
procHandle = OpenProcess(&H1 00000, True, taskId)
' check for its signaled status, return to caller
WaitForProcess = WaitForSingleOb ject(procHandle , msecs) <> -1
' close the handle
CloseHandle procHandle
End Function
====== end of code ====
having problems with handles. Here is my code ...
=====
Private Declare Function ShellExecute Lib _
"shell32.dl l" Alias "ShellExecu teA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As _
String, ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public function Shell4OD( byVal cmd as string, byVal parameters as
string, byVal Dir as string, byVal showHide as integer) As Boolean
Dim procHandle As Long, shellHnd As Long, taskID As Long
' hmmm shellHnd = ???? <=== here is my problem
taskID = ShellExecute( shellHnd, _
vbNull, cmd, parameters, Dir, showHide)
' get the process handle
procHandle = OpenProcess(&H1 00000, True, taskID)
Shell4OD = WaitForProcess( procHandle)
' close the handle
CloseHandle procHandle
end function
' Wait for a number of milliseconds, and return the running status
' of a process. If argument is omitted, wait untill the process
' terminates.
Function WaitForProcess( taskId As Long, Optional msecs As Long = -1) _
As Boolean
Dim procHandle As Long
' get the process handle
procHandle = OpenProcess(&H1 00000, True, taskId)
' check for its signaled status, return to caller
WaitForProcess = WaitForSingleOb ject(procHandle , msecs) <> -1
' close the handle
CloseHandle procHandle
End Function
====== end of code ====
Comment