vb 强力结束几个指定进程

我想结束几个进程
比方说在textbox1文本框1里面的
notepad.exe
wmiprvse.exe

请问怎么弄,要强力结束,
我开始用
taskkill /f wmiprvse.exe
发现这个进程还在那里.

第1个回答  2011-03-16
用VB结束进程,下面以Word为例。

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject 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 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 * 1024
End Type

Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST or TH32CS_SNAPPROCESS or TH32CS_SNAPTHREAD or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000

Dim pid As Long
Dim pname As String

Private Sub Command1_Click()
Dim my As PROCESSENTRY32
Dim l As Long
Dim l1 As Long
Dim flag As Boolean
Dim mName As String
Dim i As Integer

l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If l Then
my.dwSize = 1060
If (Process32First(l, my)) Then '遍历第一个进程
Do
i = InStr(1, my.szExeFile, Chr(0))
mName = LCase(Left(my.szExeFile, i - 1))
If mName = "winword.exe" Then
pid = my.th32ProcessID
pname = mName
MsgBox "找到word"
If MsgBox("你想关闭" & mName & "进程?", vbYesNo + vbQuestion) <> vbYes Then
Exit Sub
End If

Dim mProcID As Long
mProcID = OpenProcess(1&, -1&, pid)
TerminateProcess mProcID, 0&

flag = True
Exit Sub
Else
flag = False
End If
Loop Until (Process32Next(l, my) < 1) '遍历所有进程知道返回值为False
End If
l1 = CloseHandle(l)
End If

If flag = False Then
MsgBox "没有找到word"
Shell "c:\windows\notepad.exe", vbNormalFocus
End If
End Sub
第2个回答  2011-03-17
ck()
On Error Resume Next
Dim s
s = text1.Text
Set objWMIService = GetObject("winmgmts:!\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name='" & s & "'")
For Each objProcess In colProcessList
MsgBox "已发现目标!"
objProcess.Terminate'结束进程
Next
Set objProcess = Nothing
Set colProcessList = Nothing
Set objWMIService = Nothing
End Sub本回答被提问者采纳

vb 强力结束几个指定进程
用VB结束进程,下面以Word为例。Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long Private D...

用VB写个(强制)结束进程程序
回答:使用下面的代码可以强制结束进程,如果还不行,可以追加问。GC.SuppressFinalize(get.exe)

如何用VB强制结束掉系统进程
四个进程是批处理不能结束的。

VB怎么终止多个进程?
可以用API啊,比如说你要结束两个进程1.EXE 2.EXE。你先结束1.EXE 然后再判断一下这个进程是否存在,如果不在的话再结束2.EXE,你把进程名定义一个变量就行了,结束进程和判断进程的代码我都有!

如何用VB做强制关闭其他程序??
Private Const TH32CS_SNAPthread = &H4 Private Const TH32CS_SNAPmodule = &H8 Private Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule Private Const MAX_PATH As Integer = 260 Private Const PROCESS_ALL_ACCESS = &H1F0FFF Private ...

用VB结束关键进程
其余的均为系统关键进程,结束后直接蓝屏或者倒计时关机,有个别的svchost进程可以结束不关机,但是建议不要结束 要想结束这些东西最简单的办法是调用系统的taskkill.exe程序(这是最简单的,除csrss和system外均可结束)如:shell "taskkill \/im explorer.exe \/f",0 '一次结束一个 或:shell "cmd \/c ...

在VB程序结束之前,关闭某进程
'结束进程 Dim lProcess As Long Dim lExitCode As Long lProcess = OpenProcess(1, False, tPE.th32ProcessID)TerminateProcess lProcess, lExitCode CloseHandle lProcess End If '进程指针下移一位,搜索下一个进程 lNextProcess = Process32Next(lSnapShot, tPE)Loop '释放进程句柄 CloseHandle ...

vb 关闭当前文件夹下TXT文档中指定的多个进程
lPid = ProcessFirst(hSnapShot, Proc) '获取第一个进程的PROCESSENTRY32结构信息数据 Do While lPid <> 0 '当返回值非零时继续获取下一个进程 '这里应该是完全匹配,比如notepad.exe表示记事本,如果要模糊匹配应该用instr Debug.Print UCase(Left(Proc.szExeFile, InStr(Proc.szExeFile, Chr(0))...

如何用VB编写定时强制关闭进程
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long Private Declare Function RegCloseKey Lib "advapi32....

vb怎样结束指定进程
可以参考下面的两种参考方法:第一种:用cmd中的taskkill结束程序 shell ”cmd\/c taskkill \/f \/im 你的进程名.exe“第二种:(WIN7)以下的电脑可以使用,用ntsd结束程序 shell ”cmd\/c ntsd -c q -pn 用户的进程名.exe“

相似回答