Herzlichen Dank, Moritz - das ist genau das, was ich suchte. By the way - so gross bin ich gar nicht - knappe 1,90
Zusatzfrage: Was wäre, wenn ich die Task NICHT selbst starte, sondern diese bereits läuft und ich diese "abschiessen" möchte?
Bernhard
Anbei der VB-Code von Moritz, wie er unter LS funktioniert:
Declare Function WaitForSingleObject Lib "kernel32" (Byval hHandle As Long, Byval dwMilliseconds As Long) As Long
Declare Function CloseHandle Lib "kernel32" (Byval hObject As Long) As Long
Declare Function OpenProcess Lib "kernel32" (Byval dwDesiredAccess As Long, Byval bInheritHandle As Long, Byval dwProcessId As Long) As Long
Declare Function TerminateProcess Lib "kernel32" (Byval hProcess As Long, Byval uExitCode As Long) As Long
Const INFINITE = -1&
Const SYNCHRONIZE = &H100001
Sub Click (Source As Button)
Dim Task&, Handle&, Result&
Dim WaitMillis As Long
WaitMillis = 2000 '2 Sekunden
Task = Shellid ("calc.exe", SHELL_MIN_NO_FOCUS)
Handle = OpenProcess(SYNCHRONIZE, False, Task)
Result = WaitForSingleObject(Handle, WaitMillis)
If Result Then
Result = TerminateProcess(Handle, 0)
Result = CloseHandle(Handle)
Msgbox "Durch das Programm geschlossen"
Else
Msgbox "Durch den Anwender geschlossen"
End If
End Sub