Private 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
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
'Declarations
'============
Declare Sub SetWindowPos Lib "user32" _
(ByVal hWnd As Integer, _
ByVal hWndInsertAfter As Integer, _
ByVal X As Integer, _
ByVal Y As Integer, _
ByVal cx As Integer, _
ByVal cy As Integer, _
ByVal wFlags As Integer)
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Private 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
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ShellExecute Lib "shell32" 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
'Constants
'=========
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Private Const SW_SHOW = 5
Public Sub ExecAss(hWnd As Long, sCmdLine As String)
'Executes scmdline via file association ie c:\bootlog.txt will run notepad!
Dim Ret As Long
Ret = ShellExecute(hWnd, "open", sCmdLine, vbNullString, CurDir$, SW_SHOW)
If Ret < 32 Then
'Error can't shell
msgbox "Failed to execute: " & sCmdLine
End If
End Sub
Public Sub ExecCmd(sCmdLine As String)
'Executes cmdline and waits for it to finsh
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim Ret As Long
' Initialize the STARTUPINFO structure:
Start.cb = Len(Start)
' Start the shelled application:
Ret = CreateProcessA(0&, sCmdLine, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, Start, proc)
' Wait for the shelled application to finish:
Ret = WaitForSingleObject(proc.hProcess, INFINITE)
Ret = CloseHandle(proc.hProcess)
End Sub