VB: Warten bis externes Programm gestartet ist

… kann ich in VB irgendwie warten, bis ein externes Programm vollständig geladen ist, welches ich mit SHELL „blabla.exe“ aufrufe?

… kann ich in VB irgendwie warten, bis ein externes Programm
vollständig geladen ist, welches ich mit SHELL „blabla.exe“
aufrufe?

Versuchs mal damit (einzelne EXE)…
Wenn Du mehrere Dateien hintereinander Starten möchtest, dann
erstell Dir eine Ini-Datei und lies die Exe´s hintereinander ein.

'Schreib das in eine Form-Prozedur

SyncShell "c:\Irgendeine.exe", 0, False, False

'Schreib das in eine BAS
Option Explicit

Public Const NORMAL\_PRIORITY\_CLASS As Long = &H20&
Public Const INFINITE As Long = -1&
Public Const STATUS\_WAIT\_0 As Long = &H0
Public Const WAIT\_OBJECT\_0 As Long = STATUS\_WAIT\_0

Private Declare Function InputIdle Lib "user32" Alias "WaitForInputIdle" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function WaitForSingleObject Lib "Kernel32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function CloseHandle Lib "Kernel32" (ByVal hObject 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

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 Function SyncShell(CommandLine As String, Optional Timeout As Long, \_
 Optional WaitForInputIdle As Boolean, Optional Hide As Boolean = False) As Boolean

 Dim hProcess As Long

 Dim ret As Long
 Dim nMilliseconds As Long

 If Timeout \> 0 Then
 nMilliseconds = Timeout
 Else
 nMilliseconds = INFINITE
 End If

 hProcess = StartProcess(CommandLine, Hide)

 If WaitForInputIdle Then
 ' Warten, bis die eingeschlossene Anwendung
 ' mit dem Erstellen ihrer Schnittstelle fertig ist:
 ret = InputIdle(hProcess, nMilliseconds)
 Else
 ' Warten, bis die eingeschlossene Anwendung beendet ist:
 ret = WaitForSingleObject(hProcess, nMilliseconds)
 End If

 CloseHandle hProcess

 ' "True" zurückgeben, wenn die Anwendung fertig ist.
 ' Andernfalls Zeitüberschreitung oder Fehler.
 SyncShell = (ret = WAIT\_OBJECT\_0)
End Function


Public Function StartProcess(CommandLine As String, Optional Hide As Boolean = False) As Long
 Const STARTF\_USESHOWWINDOW As Long = &H1
 Const SW\_HIDE As Long = 0

 Dim proc As PROCESS\_INFORMATION
 Dim Start As STARTUPINFO

 ' STARTUPINFO-Struktur initialisieren:
 Start.cb = Len(Start)
 If Hide Then
 Start.dwFlags = STARTF\_USESHOWWINDOW
 Start.wShowWindow = SW\_HIDE
 End If
 ' Eingeschlossene Anwendung starten:
 CreateProcessA 0&, CommandLine, 0&, 0&, 1&, \_
 NORMAL\_PRIORITY\_CLASS, 0&, 0&, Start, proc

 StartProcess = proc.hProcess
End Function

Gruß Matthias