先说下基本思路吧。
首先得到进程ID(EnumProcesses),获得进程句柄(OpenProcess),再用TerminateProcess 杀死它。
'
3460是刚才系统给记事本分配的ID
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
Const
PROCESS_TERMINATE
=
&
H1
Private
Sub
Command2_Click()
Dim
hand
As
Long
'
hand = OpenProcess(PROCESS_TERMINATE, True, Process.th32ProcessID) '获取进程句柄
'
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION+SYNCHRONIZE,FALSE,pid)
hand
=
OpenProcess(PROCESS_TERMINATE,
True
,
3460
)
TerminateProcess hand,
0
'
关闭进程
End Sub
本文介绍了一种通过获取进程ID,打开进程句柄,并最终调用TerminateProcess函数来终止指定进程的方法。涉及的关键步骤包括使用EnumProcesses获取进程ID,利用OpenProcess函数获取句柄,最后通过TerminateProcess函数结束进程。
675

被折叠的 条评论
为什么被折叠?



