vb 如何终止外部程序中的某个线程
要结束线程:用PROCESS打开程序,线程选卡中 PID:3224 启动地址drcomdll.dll+0x1700 的线程
ps:用process可以结束,但每次都要弄,麻烦,想弄个程序~~~ --------------------编程问答-------------------- 有办法,关闭电源! --------------------编程问答-------------------- LS有够..,希望给点实质性的方案 --------------------编程问答-------------------- 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 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 Module32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As MODULEENTRY32) As Long
Private Declare Function Module32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As MODULEENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) 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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_CLOSE = &H10
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
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPmodule = &H8
Private Type MODULEENTRY32
dwSize As Long
th32ModuleID As Long
th32ProcessID As Long
GlblcntUsage As Long
ProccntUsage As Long
modBaseAddr As Byte
modBaseSize As Long
hModule As Long
szModule As String * 256
szExePath As String * 1024
End Type
Private Sub Form_Load()
Timer1.Interval = 100 '设置Timer1控件的事件触发时间间隔
End Sub
Private Sub Timer1_Timer()
Dim clsHw As Long
clsHw = FindWindow(vbNullString, "扫雷") '查找是否存在"扫雷"程序
If clsHw <> 0 Then
SendMessage clsHw, WM_CLOSE, 0&, 0& '关闭找到的这个程序
End If
End Sub
--------------------编程问答-------------------- 使用TerminalThread函数即可. --------------------编程问答-------------------- VB下实现线程编程?是进程吧? --------------------编程问答-------------------- 最简洁的代码,支持VB、VBA、VBS、WSH、HTA:
--------------------编程问答-------------------- 直接用DOS外部命令:Kill
Dim objWMIService, colProcessList
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name='racer.exe'")
For Each objProcess In colProcessList
objProcess.Terminate
Next
补充:VB , API