程序一进入就运行c:\calc.exe(相当于你的exe),程序退出时 calc.exe同步退出,(当然进程里面也会退出)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 TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Const PROCESS_TERMINATE = 1 Dim Fname$, ProID&, hProcess&Private Sub Form_Load() Fname = "c:\calc.exe" '改为你的 exe If Dir(Fname) <> "" Then ProID = Shell(Fname, vbNormalFocus) End SubPrivate Sub Form_Unload(Cancel As Integer) On Error Resume Next If Dir(Fname) <> "" Then hProcess = OpenProcess(PROCESS_TERMINATE, False, ProID) TerminateProcess hProcess, 1 CloseHandle hProcess End If End End Sub
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Const PROCESS_TERMINATE = 1
Dim Fname$, ProID&, hProcess&Private Sub Form_Load()
Fname = "c:\calc.exe" '改为你的 exe
If Dir(Fname) <> "" Then ProID = Shell(Fname, vbNormalFocus)
End SubPrivate Sub Form_Unload(Cancel As Integer)
On Error Resume Next
If Dir(Fname) <> "" Then
hProcess = OpenProcess(PROCESS_TERMINATE, False, ProID)
TerminateProcess hProcess, 1
CloseHandle hProcess
End If
End
End Sub