Option Explicit
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long)
Private Sub Command1_Click()
Dim taskID As Double
taskID = Shell("notepad.exe", vbNormalFocus)
' ... code ...
KillShell taskID
End Sub
Private Sub KillShell(ByVal taskID As Double)
On Error Resume Next
Dim hProcess As Long
Dim lExitCode As Long
Dim lRet As Long
If taskID <> 0 Then
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, taskID)
If hProcess <> 0 Then
GetExitCodeProcess hProcess, lExitCode
If lExitCode <> 0 Then
TerminateProcess hProcess, lExitCode
End If
End If
End If
End Sub
Shell "c:\myApp2.exe"
the problem comes when you want to close it... for that you need to use Windows API...