Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
Public 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
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
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 ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (_
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
Declare Function CloseHandle Lib "kernel32" (Byval hObject As Long) As Long
Dim RetVal As Long
Dim proc As PROCESS_INFORMATION
Dim StartInf As STARTUPINFO
Private Function ShellAndWait(Byval RunProg As String) As Long
StartInf.cb = Len(StartInf)
StartInf.wShowWindow = 0&
RetVal = CreateProcessA(0&, RunProg, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc)
RetVal = WaitForSingleObject(proc.hProcess, INFINITE)
RetVal = CloseHandle(proc.hProcess)
ShellAndWait = RetVal
End Function
Function RunExternalProgram(CmdLine As String) As Boolean
On Error Goto Errh
If CmdLine = "" Then Exit Function
Dim Result As Long
Result = ShellAndWait(CmdLine)
RunExternalProgram = True
Exit Function
Errh:
Exit Function
End Function