Hier mal der Code, mit dem ich eine Anwendung starte und auf Beendigung selbiger warte, vielleicht hilft es dir weiter:
Public Const INFINITE As Long = -1&
Public Const NORMAL_PRIORITY_CLASS As Long = &H20&
Private Declare Function CreateProcess Lib "kernel32.dll" Alias _
"CreateProcessA" ( _
ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByRef lpProcessAttributes As SECURITY_ATTRIBUTES, _
ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByRef lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
ByRef lpStartupInfo As STARTUPINFO, _
ByRef lpProcessInformation As PROCESS_INFORMATION _
) As Long
Private Declare Function CreateProcessByNum Lib "kernel32.dll" Alias _
"CreateProcessA" ( _
ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByRef lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
ByRef lpStartupInfo As STARTUPINFO, _
ByRef lpProcessInformation As PROCESS_INFORMATION _
) As Long
Private Declare Function WaitForSingleObject Lib "kernel32.dll" ( _
ByVal hHandle As Long, _
ByVal dwMilliseconds As Long _
) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" ( _
ByVal hObject As Long _
) As Long
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
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
Public Sub ExecuteAndWait( _
cmdline As String, _
Optional ByVal waitMs As Long = INFINITE _
)
Dim NameOfProc As PROCESS_INFORMATION
Dim NameStart As STARTUPINFO
Dim sa As SECURITY_ATTRIBUTES
Dim x As Long
On Error Resume Next
sa.nLength = Len(sa)
sa.bInheritHandle = True
NameStart.cb = Len(NameStart)
x = CreateProcess( _
cmdline, _
vbNullString, _
sa, sa, _
True, _
NORMAL_PRIORITY_CLASS, _
0&, 0&, _
NameStart, NameOfProc _
)
x = CreateProcessByNum( _
cmdline, _
vbNullString, _
0, 0, _
True, _
NORMAL_PRIORITY_CLASS, _
ByVal 0&, _
vbNullString, _
NameStart, _
NameOfProc _
)
Debug.Assert Err = 0
If waitMs <= 0 Then
waitMs = INFINITE
End If
x = WaitForSingleObject(NameOfProc.hProcess, waitMs)
x = CloseHandle(NameOfProc.hProcess)
Debug.Assert Err = 0
End Sub Gruß
Dirk
--
?Get it right the first time  |