Hi,
ich will über eine form mit einem Klick auf einen button eine .exe ausführen. Sobald die .exe fertig ist, soll eine Meldung erscheinen.
Google hat mir dann die Funktion "shellx" vorgeschlagen. Dies soll mir eine Rückmeldung geben, wann die .exe bzw der Prozess fertig ist.
Bekomm dies jedoch nicht hin.
Diesen Code habe ich gefunden, die die Funktion shellx integrieren soll. Jedoch kennt mein VB z.b. "VAppWinStyle" nicht.
Ich hoffe ihr könnt mir weiter helfen.
ich will über eine form mit einem Klick auf einen button eine .exe ausführen. Sobald die .exe fertig ist, soll eine Meldung erscheinen.
Google hat mir dann die Funktion "shellx" vorgeschlagen. Dies soll mir eine Rückmeldung geben, wann die .exe bzw der Prozess fertig ist.
Bekomm dies jedoch nicht hin.
Diesen Code habe ich gefunden, die die Funktion shellx integrieren soll. Jedoch kennt mein VB z.b. "VAppWinStyle" nicht.
VB.NET-Quellcode
- Private Declare Function CloseHandle Lib "kernel32" ( _
- ByVal hObject As Long) As Long
- Private Declare Function GetExitCodeProcess Lib "kernel32" ( _
- ByVal hProcess As Long, ByVal lpExitCode As Long) As Long
- Private Declare Function OpenProcess Lib "kernel32" ( _
- ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
- ByVal dwProcessId As Long) As Long
- ' ShellX stellt eine Erweiterung der Shell-Funktion von VBA dar, die es erlaubt,
- ' das Ende des ausgeführten Prozesses abzuwarten
- Public Function ShellX( _
- ByVal PathName As String, _
- Optional ByVal WindowStyle As VAppWinStyle = vbMinimizedFocus, _
- Optional ByVal Events As Boolean = True _
- ) As Long
- 'Deklarationen:
- Const STILL_ACTIVE = &H103&
- Const PROCESS_QUERY_INFORMATION = &H400&
- Dim ProcId As Long
- Dim ProcHnd As Long
- 'Prozess-Handle holen:
- ProcId = Shell(PathName, WindowStyle)
- ProcHnd = OpenProcess(PROCESS_QUERY_INFORMATION, True, ProcId)
- 'Auf Prozess-Ende warten:
- Do
- If Events Then DoEvents()
- GetExitCodeProcess(ProcHnd, ShellX)
- Loop While ShellX = STILL_ACTIVE
- 'Aufräumen:
- CloseHandle(ProcHnd)
Ich hoffe ihr könnt mir weiter helfen.