GFShell/GFShellmod.bas
Attribute VB_Name = "GFShellmod"
'(c)2009 by Louis. Functions concerning the VB Shell() command.
'
'NOTE: code partially copied from http://support.microsoft.com/kb/96844 (21.02.2009).
'NOTE: the whole stuff looks a bit 16‑bit old‑styled. Nevertheless it seems to work :]
'Ask Microsoft if there's a newer version available...
'No forget it, does not work. Found new code. Have a look at this:
'
' ShellWat sample by Matt Hart ‑ mhart@taascforce.com
' http://www.webczar.com/defcon/mh/vbhelp.html
' http://www.webczar.com/defcon/mh
' ' Shows how to shell to another program, and wait until it finishes
' before continuing.
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject 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 Const INFINITE = ‑1&
Private Const SYNCHRONIZE = &H100000
Public Sub GFShell_RunAndWait(ByVal RunName As String, ByVal WaitTimeInMs As Long)
On Error GoTo Error: 'important; pass WaitTimeInMs = ‑1 to wait forever
Dim ProcessHandle As Long
Dim Temp As Long
'begin
Temp = Shell(RunName, vbNormalFocus)
If Temp = 0 Then Exit Sub 'verify
ProcessHandle = OpenProcess(SYNCHRONIZE, False, Temp)
Temp = WaitForSingleObject(ProcessHandle, WaitTimeInMs)
Temp = CloseHandle(ProcessHandle)
Exit Sub
Error:
Exit Sub
End Sub
[END OF FILE]