你想关闭某个进程是吧..发个代码你看看
此代码调用下面程序...
'查找进程
if FindProcess("qq.exe")=true then
msgbox "QQ进程存在!"
end if
'结束进程
CloseProcess "qq.exe"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Public Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode 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 Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const PROCESS_TERMINATE = 1
Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * 260
End Type
Private Type MyProcess
ExeName As String
Pid As Long
End Type
Public Function CloseProcess(ByVal ProName As String) As Integer
Dim tPID As Long
Dim tPHwnd As Long
If FindProcess(ProName, tPID) = False Then
Exit Function
Else
tPHwnd = OpenProcess(PROCESS_TERMINATE, False, tPID)
Debug.Print tPHwnd
If tPHwnd Then
CloseProcess = TerminateProcess(tPHwnd, 0)
End If
End If
End Function
Public Function FindProcess(ByVal ProName As String, Optional ByRef Pid As Long) As Boolean
Dim MyProcess As PROCESSENTRY32
Dim mySnapshot As Long
Dim ProData() As MyProcess
ReDim ProData(0)
MyProcess.dwSize = Len(MyProcess)
mySnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
ProcessFirst mySnapshot, MyProcess
ReDim Preserve ProData(UBound(ProData) + 1)
ProData(UBound(ProData)).ExeName = Left(MyProcess.szexeFile, InStr(MyProcess.szexeFile, Chr(0)) - 1)
ProData(UBound(ProData)).Pid = MyProcess.th32ProcessID
'Debug.Print ProData(UBound(ProData)).ExeName
If LCase(ProData(UBound(ProData)).ExeName) = LCase(ProName) Then
FindProcess = True
Pid = ProData(UBound(ProData)).Pid
Exit Function
End If
MyProcess.szexeFile = ""
While ProcessNext(mySnapshot, MyProcess)
ReDim Preserve ProData(UBound(ProData) + 1)
ProData(UBound(ProData)).ExeName = Left(MyProcess.szexeFile, InStr(MyProcess.szexeFile, Chr(0)) - 1)
ProData(UBound(ProData)).Pid = MyProcess.th32ProcessID
' Debug.Print ProData(UBound(ProData)).ExeName
If LCase(ProData(UBound(ProData)).ExeName) = LCase(ProName) Then
FindProcess = True
Pid = ProData(UBound(ProData)).Pid
Exit Function
End If
MyProcess.szexeFile = ""
Wend
End Function