如何用VB中止一个进程

来源:百度知道 编辑:UC知道 时间:2024/05/18 16:18:06
知道进程名,比如我想把QQ.exe这个进程杀掉,应该怎么做呢

最好粘点代码上来,不要太烦琐的,是不是要先或得进程句炳啊

搞手半天也没搞明白,高手们帮帮忙吧

'代码写在模块里

Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Const PROCESS_TERMINATE = &H1
Sub main()
Dim hwnd As Long
Dim pid As Long
Dim lngProcess As Long
dim sTemp as string
sTemp="电卓" '-------------------"你要杀掉的进程名"
hwnd = FindWindow(vbNullString, "电卓")
Call GetWindowThreadProcessId(hwnd, pid)
lngProcess = OpenProcess(PROCESS_TERMINATE