寻求杀进程代码(望高手赐教)
我现在在学写程序,我有点vb基础,我想弄点代码来自己学习学习,望高手能给我杀进程的代码,我非常的感激
我先前在很多论坛里面发过,好象都没人回过,现在我来到计算机高手云集的地方,望帮忙
[解决办法]
Option Explicit
Private Const MAX_PATH As Integer = 260
Private Const TH32CS_SNAPPROCESS = &H2
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private 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 * MAX_PATH
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll " (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll " (ByVal hObject As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32.dll " Alias "Process32First " (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32.dll " Alias "Process32Next " (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function OpenProcess Lib "kernel32.dll " (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32.dll " (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32.dll " (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Sub Command1_Click()
Dim ret As Long
ret = CloseTargetProcess( "sss.exe ")
If ret = 0 Then
MsgBox "终止进程失败 "
Else
MsgBox "进程已被终止 "
End If
End Sub
Private Function CloseTargetProcess(ByVal lpProcess As String) As Boolean
Dim dwProcessId As Long
Dim hSnapShot As Long
Dim pe32 As PROCESSENTRY32
Dim hProcess As Long
Dim lpExitCode As Long
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
pe32.dwSize = LenB(pe32)
ProcessFirst hSnapShot, pe32
Do
If Replace(pe32.szExeFile, Chr$(0), " ") = lpProcess Then
dwProcessId = pe32.th32ProcessID
Exit Do
Else
pe32.szExeFile = String(MAX_PATH, 0)
End If
Loop While (ProcessNext(hSnapShot, pe32))
CloseHandle (hSnapShot)
If dwProcessId = 0 Then
CloseTargetProcess = False
Exit Function
End If
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, dwProcessId)
If hProcess = 0 Then
CloseTargetProcess = False
Exit Function
End If
If GetExitCodeProcess(hProcess, lpExitCode) = 0 Then
CloseTargetProcess = False
CloseHandle (hProcess)
Exit Function
End If
If TerminateProcess(hProcess, lpExitCode) = 0 Then
CloseTargetProcess = False
Else
CloseTargetProcess = True
End If
CloseHandle (hProcess)
End Function