'--------- Anfang Formular "Form1" alias Form1.frm ---------
' Steuerelement: Textfeld "Text1"
' Steuerelement: Schaltfläche "Command1"
' Steuerelement: Beschriftungsfeld "Label1"
Option Explicit
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) _
As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal _
dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal _
hProcess As Long, ByVal uExitCode As Long) As Long
Const INFINITE = -1&
Const SYNCHRONIZE = &H100000
Private Sub Form_Load()
Text1.Text = 1000
End Sub
Private Sub Command1_Click()
Dim Task&, Handle&, Result&
Task = Shell("notepad.exe", vbNormalFocus)
Handle = OpenProcess(SYNCHRONIZE, False, Task)
Result = WaitForSingleObject(Handle, CLng(Text1.Text))
AppActivate Me.Caption
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