
Using the Shell function to run a program asynchronously
On Mon, 1 Jun 1998 22:13:46 +0200, "Harry van Nyendaal"
Quote:
>Hi,
>I'm using the Shell function to e.g. ZIP-files.
>How can I detemine that the ZIP-program is ready?
Another way to phrase the question (and come closer to a solution) is
"How can I determine when PKZIP is finished doing its business?" In
other words, "How can I determine when a DOS program has finished
executing?"
Try using this code:
---------------------
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STILL_ACTIVE = &H103&
' the following three API functions must be typed ALL ON ONE LINE
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal
hProcess As Long, lpExitCode As Long) 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
Sub WaitForDOSApp(cmd As String)
Dim ProcessId As Long, hProcess As Long
Dim ExitCode As Long
ProcessId = Shell(cmd, vbMinimizedNoFocus)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, _
False, ProcessId)
Do
Call GetExitCodeProcess(hProcess, ExitCode)
DoEvents
Loop While (ExitCode = STILL_ACTIVE)
Call CloseHandle(hProcess)
End Sub
-----------------------------------------------------------
To use the above subroutine, pass the it command line you wish to
execute. For example:
WaitForDOSApp "c:\pkware\pkz204g.exe myfile.zip c:\*.doc"
The function will wait until the command is finish executing before
returning control to the Form or Subroutine which called it. But note
the "DoEvents" call--this allows your form to process other events
while it is waiting.
:) Pirate Pete the Christian Privateer :)
:) aka Jack Voltz :)
:) M A R A N A T H A ! :)
Web page: http://www.ovnet.com/~voltz
Prolife page: http://www.ovnet.com/~voltz/prolife.htm
Music: http://www.ovnet.com/~voltz/music.htm