VB怎么绕过QueryUnload事件直接关闭程序

如题~即强行关闭运行中的程序。最近的分都全部给扣掉了,所以不敢打分。如遇正解一定给分!SendMessage 我老早就用过了,无法逃脱外部进程的关闭检测。无用...
2026年09月23日 17:50
有3个网友回答
网友(1):

用API函数,我给你介绍一下,挺实用的:

先在声明中添加:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_CLOSE = &H10

这些用来寻找窗口句柄。

那么如何结束进程呢?
用这个代码

hProcess = FindWindow(vbNullString, "在这里填上你想结束的程序名称,如“windows 任务管理器”")
SendMessage hProcess, WM_CLOSE, 0, 0

就以任务管理器为例
hProcess = FindWindow(vbNullString, "windows 任务管理器")
SendMessage hProcess, WM_CLOSE, 0, 0

这个程序运行时,如果扫描到窗口有程序名叫“windows 任务管理器”的话,立刻就被结束掉了,想都不用想!

注明:2楼的所谓的end只是结束自身程序而已

网友(2):

用这个吧,我还以为你用在自身程序呢.

'禁止"Explorer"运行

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub StopExplorer()
Dim i As Integer
For i = 1 To 10
Call Shell("tskill explorer", 0)'你得知道它的名字,否则用列表枚举出来代码可多着呢.
Sleep 100
Next
End Sub

'*****************************************************

'###################禁止进程函数####################

'禁止进程函数的Bas文件,可以禁止监视的进程拒绝运行.

'编写作者:刘俊宾

'作者主页:http://hystudio.ik8.com

'编写日期:2007年1月15日

'示例:
'#######################################################################
'# If LookTask("Windows 任务管理器",True)=True Then # 监视"Windows 任务管理器"是否在运行(需配合Timer控件使用)[标题方式]
'# StopText("Windows 任务管理器",True) # 禁止"Windows 任务管理器"运行(需配合Timer控件使用)[标题方式]
'# StopName("taskmgr",False) # 禁止"Windows 任务管理器"运行(需配合Timer控件使用)[进程方式]
'# StopExplorer # 禁止"Explorer"运行
'# StopTask # 禁止"taskmgr"运行
'# StopRegedit # 禁止"regedit"运行
'#######################################################################

网友(3):

用API啊,检索进程,然后咔嚓结束,吱都来不及吱一声