Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Const NORMAL_PRIORITY_CLASS = &H20&
Const INFINITE = -1&
Declare Function WaitForSingleObject Lib "kernel32" (Byval _
hHandle As Long, Byval dwMilliseconds As Long) As Long
Declare Function CreateProcessA Lib "kernel32" (Byval _
lpApplicationName As Long, Byval lpCommandLine As String, Byval _
lpProcessAttributes As Long, Byval lpThreadAttributes As Long, _
Byval bInheritHandles As Long, Byval dwCreationFlags As Long, _
Byval lpEnvironment As Long, Byval lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Declare Function GetExitCodeProcess Lib "kernel32" _
(Byval hProcess As Long, lpExitCode As Long) As Long
'______________________________________
Function fShellWait(strCmdLine As String) As Long
'--- Shells the passed command line and waits for the process to finish
'--- Returns the exit code of the shelled process
Dim udtProc As PROCESS_INFORMATION, udtStart As STARTUPINFO
Dim lngRtn As Long
'Initialize the STARTUPINFO structure
udtStart.cb = Len(udtStart)
'Launch the shelled application and yield to it
lngRtn = CreateProcessA(Clng(0), strCmdLine, Clng(0), Clng(0), Clng(1), _
NORMAL_PRIORITY_CLASS, Clng(0), Clng(0), udtStart, udtProc)
DoEvents
'Wait for the shelled application to finish
lngRtn = WaitForSingleObject(udtProc.hProcess, INFINITE)
Call GetExitCodeProcess(udtProc.hProcess, lngRtn)
Call CloseHandle(udtProc.hThread)
Call CloseHandle(udtProc.hProcess)
fShellWait = lngRtn
End Function