|
欢迎您注册加入!这里有您将更精采!
您需要 登录 才可以下载或查看,没有账号?注册
x
这几天闲来无事玩了玩DNF 退出游戏的时候觉得N慢 想了想直接结束进程是最快的所以突发奇想写出的 请各位大虾们指点
Form1:
--------------------------------------------------调用方法---------------------------------------------------
- Private Sub Command1_Click()
- TerminateFileName "你要结束的进程名字"
- End Sub
- 例如:
- Private Sub Command1_Click()
- TerminateFileName "QQLogin.exe"
- End Sub
复制代码 模块:
--------------------------------------------------Module1.bas------------------------------------------------
- Option Explicit
- Public Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
- 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 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 Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
- Public Const TH32CS_SNAPPROCESS = &H2
- Public Const TH32CS_SNAPheaplist = &H1
- Public Const TH32CS_SNAPthread = &H4
- Public Const TH32CS_SNAPmodule = &H8
- Public Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule
- Public Const MAX_PATH As Integer = 260
- Public Const PROCESS_TERMINATE = &H1
- Public 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
- Public Sub TerminateFileName(FileName As String)
- Dim proc As PROCESSENTRY32
- Dim snap As Long
- Dim exename As String
- Dim theloop As Long
- Dim hand As Long
- Dim FileID As Long
- snap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0)
- proc.dwSize = Len(proc)
- theloop = ProcessFirst(snap, proc)
- While theloop <> 0
- exename = proc.szExeFile
- If Left(Trim(LCase(exename)), Len(FileName)) = LCase(FileName) Then
- FileID = proc.th32ProcessID
- hand = OpenProcess(PROCESS_TERMINATE, True, FileID)
- TerminateProcess hand, 0
- CloseHandle snap
- Exit Sub
- End If
- theloop = ProcessNext(snap, proc)
- Wend
- CloseHandle snap
- End Sub
复制代码 请大家不要见笑啊···· By:Mythhack |
|