On Tue, 18 Nov 2003 12:08:58 -0000, "J Bunton"
<jB*****@BlueYonder.co.uk> wrote:
ShellStr = "C:\temp\wzzip " & ZipOptions & " " & ZipTo & " " & ZipFrom
ShellRet=Shell(ShellStr)
. . . . . .
msgbox "Done"
How can I determin whether the Shelled process is still running.
[I want to delay the Done message until the shelled process has completed]
Here is my testbed for this
- it looks like I lifted most of it from somewhere
- there is a pretty good case for using CreateProcess rather than
Shell
Option Explicit
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
Private Const SYNCHRONIZE = &H100000
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Declare Function GetExitCodeProcess _
Lib "kernel32" _
(ByVal hProcess As Long, _
lpExitCode As Long) As Long
Dim pID As Long
Sub Form_Load()
Command1.Caption = "Shell"
Command2.Caption = "Get Status"
End Sub
Private Sub Command2_Click()
Dim Ok&, ECode&
Dim hProcess&, Q&
Q = PROCESS_QUERY_INFORMATION Or SYNCHRONIZE
hProcess = OpenProcess(Q, False, pID)
' ---
Ok = GetExitCodeProcess(hProcess, ECode)
MsgBox Str$(Ok) + Str$(ECode)
' ---
If hProcess Then
CloseHandle hProcess
End If
End Sub
Sub Command1_Click()
Dim Style%, Cmd$
' Style = vbHide
Style = vbNormalFocus
Cmd$ = "DIR C:\ /P"
pID = Shell(Environ("Comspec") + " /C " + Cmd, Style)
End Sub