Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode 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 CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Const PROCESS_TERMINATE = 1
Dim ProID As Long
Dim strpath As String
Dim mm
Private Sub Command1_Click()
Command1.Enabled = False
Command2.Enabled = True
mm = Val(Text2.Text) * 1000
strpath = Text1.Text
ProID = Shell(strpath, vbNormalFocus)
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
Command1.Enabled = True
Command2.Enabled = False
End Sub
Private Sub Form_Load()
Command2.Enabled = False
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim hProcess As Long
Dim i
i = GetTickCount()
Do Until GetTickCount() > i + mm
DoEvents
Loop
hProcess = OpenProcess(PROCESS_TERMINATE, False, ProID)
TerminateProcess hProcess, 1
CloseHandle hProcess
ProID = Shell(strpath, vbNormalFocus)
End Sub