|
2楼的简单是简单,但是如果同时打开多个进程的话,会关闭所有。
下面代码,打开哪个就关闭哪个。- 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
- Dim hProcess As Long
- Private Sub Command1_Click() '打开进程
- Dim pid As Long
- pid = Shell("calc.exe", vbNormalFocus)
- hProcess = OpenProcess(&H1, 0, pid)
- End Sub
- Private Sub Command2_Click() '关闭进程
- TerminateProcess hProcess, 1
- End Sub
复制代码 |
|