vb 禁止结束进程本程序进程专门针对任务管理器 。
思路:将kernel32的TerminateProcess的首字节改为HC3 , 使TerminateProcess失效 。
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long '
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Const TH32CS_SNAPPROCESS = H2
Private Const TH32CS_SNAPheaplist = H1
Private Const TH32CS_SNAPthread = H4
Private Const TH32CS_SNAPmodule = H8
Private Const TH32CS_SNAPall = TH32CS_SNAPPROCESSTH32CS_SNAPheaplistTH32CS_SNAPthreadTH32CS_SNAPmodule
Private Const MAX_PATH As Integer = 260
Private Const PROCESS_ALL_ACCESS = H100000HF0000HFFF
Private Type PROCESSENTRY32
dwSize As Long
cntUseage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
swFlags As Long
szExeFile As String * 1024
End Type
Private Sub AntiKill()
On Error Resume Next
Dim MySnapHandle As Long
Dim hProcess As Long
Dim ProcessInfo As PROCESSENTRY32
Dim Addr As Long, hMod As Long
Dim ASM(0) As Byte
Dim sProcess As String
ASM(0) = HC3'retn
hMod = GetModuleHandle("kernel32")
Addr = GetProcAddress(hMod, "TerminateProcess")
'Debug.Print Hex(Addr)
MySnapHandle = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0)
ProcessInfo.dwSize = Len(ProcessInfo)
If ProcessFirst(MySnapHandle, ProcessInfo)0 Then
Do
sProcess = Left(LCase(ProcessInfo.szExeFile), InStr(ProcessInfo.szExeFile, ".")3)
If sProcess = "taskmgr.exe" Then
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessInfo.th32ProcessID)
'Debug.Print hProcess
WriteProcessMemory hProcess, ByVal Addr, ByVal VarPtr(ASM(0)), 1, 0
'Debug.Print Err.LastDllError
CloseHandle hProcess
End If
Loop While ProcessNext(MySnapHandle, ProcessInfo)0
End If
CloseHandle MySnapHandle
Err.Clear
End Sub
vb.net 怎么结束进程好像不难吧vb.net禁止结束进程?
vb.net禁止结束进程我放进vb.net禁止结束进程了Button1的Click事件里 。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
On Error GoTo Errmessages'在做系统操作时加排错标签是个好习惯
Dim TargetName As String = "ibmdict" '存储进程名为文本型,注vb.net禁止结束进程:进程名不加扩展名
Dim TargetKill() As Process = Process.GetProcessesByName(TargetName) '从进程名获取进程
Dim TargetPath As String'存储进程路径为文本型
If TargetKill.Length1 Then'判断进程名的数量,如果同名进程数量在2个以上,用For循环关闭进程 。
For i = 0 To TargetKill.Length - 1
TargetPath = TargetKill(i).MainModule.FileName
TargetKill(i).Kill()
Next
ElseIf TargetKill.Length = 0 Then'判断进程名的数量,没有发现进程直接弹窗 。不需要的,可直接删掉该If子句
MsgBox("没有发现进程vb.net禁止结束进程!")
Exit Sub
ElseIf TargetKill.Length = 1 Then'判断进程名的数量,如果只有一个,就不用For循环
TargetKill(0).Kill()
End If
MsgBox("已终止"TargetKill.Length"个进程") '弹窗提示已终止多少个进程
Errmessages:‘定义排错标签
If Err.DescriptionNothing Then’判断有无错误,如果有,则 ↓
MsgBox(Err.Description) '当出现错误时,弹窗提示
End If
End Sub
可根据需要自行修改,这个备注够完善了吧?不会的再Hi我 。
VB编写的VBS如何防止别人结束进程在你的脚本中加入:strComputer = "."
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")objProcess.Create("wscript.exe C:\PRO.VBS")
Set objWMIService = GetObject("winmgmts:" _
"{impersonationLevel=impersonate}!\\"strComputer"\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancedeletionevent " _
"within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
Set objLatestProcess = colMonitoredProcesses.NextEvent
if instr(ucase(objLatestProcess.TargetInstance.commandline),"C:\PRO.VBS") then
objProcess.Create("wscript.exe C:\PRO.VBS")
end if
Loop
其中C:\PRO.VBS就是起保护作用的脚本路径,你可以自行建立(C:\PRO.VBS必须要大写) 现在新建一个保护脚本,路径和上面的C:\PRO.VBS要一致strComputer = "."
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")Set objWMIService = GetObject("winmgmts:" _
"{impersonationLevel=impersonate}!\\"strComputer"\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancedeletionevent " _
"within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
Set objLatestProcess = colMonitoredProcesses.NextEvent
if instr(ucase(objLatestProcess.TargetInstance.commandline),"C:\TEST.VBS") then
objProcess.Create("wscript.exe C:\TEST.VBS")
end if
Loop其中C:\TEST.VBS,就是你的主脚本路径,根据实际情况该写,但是C:\TEST.VBS需要大写 直接运行你的主脚本C:\TEST.VBS即可,不需要你手动运行保护脚本
vb.net怎么结束进程?先获得那个进程vb.net禁止结束进程的Process,再用Processvb.net禁止结束进程的Kill方法来强行关闭
vb.net 如何防止程序重复运行?现在多是在form_load里验证的,你打开第二次也只是暂时的,后面让他关闭就行了.
form_load之前windows form就已经生成... 把你程序读入内存就算这个程序已经被打开开始执行了...不管你放那里都是会打开第二次的...
要让他结束直接用Application.Exit()就行了.
怎样才能用VB.NET的代码来关闭一个在运行的程序软糖来回答罗vb.net禁止结束进程:通过System.Diagnostics命名空间下vb.net禁止结束进程的Process类来关闭程序vb.net禁止结束进程的进程
Dim 进程集合 = Process.GetProcessesByName("进程名称")
For Each 进程 In 进程集合
进程.Kill()
'进程.Close() '或者使用关闭
Next
也可以先获取所有进程vb.net禁止结束进程,再来判断这些进程的名称ProcessName
Dim 获取本地所有进程 = Process.GetProcesses()
For Each 进程 In 获取本地所有进程
If 进程.ProcessName = "explorer.exe" Then 进程.Kill()
Next
【vb.net禁止结束进程 vbnet关闭窗体不让退出】vb.net禁止结束进程的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于vbnet关闭窗体不让退出、vb.net禁止结束进程的信息别忘了在本站进行查找喔 。
推荐阅读
- linux怎么查历史命令,linux查历史命令带关键字
- 单机沙盒射击游戏,沙盒类射击游戏手游
- 前几年的斗鱼直播,当年的斗鱼
- windows系统在哪下的简单介绍
- 怎么将网络改成公用路由器,怎么将无线网的公用网改为家庭
- 直播换平台是什么原因,直播换平台会不会起诉
- postgresql设置远程访问,plsql 远程
- 如何关闭oracle 如何关闭Oracle数据库服务器
- more命令在linux,linux常用命令more