在 Vbscript 中终止进程
我试图终止名为“AetherBS.exe”的进程的所有实例,但以下 VBscript 不起作用。我不太确定在哪里/为什么会失败。
那么我怎样才能杀死“AetherBS.exe”的所有进程呢?
CloseAPP "AetherBS.exe"
Function CloseAPP(Appname)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Process", , 48)
For Each objItem In colItems
If InStr(1,Ucase(objItem.Name),Appname) >= 1 Then
objItem.Terminate
End If
Next
End Function
I am trying to kill all instances of a process called "AetherBS.exe" but the following VBscript is not working. I am not exactly sure where/why this is failing.
So how can I kill all process of "AetherBS.exe?"
CloseAPP "AetherBS.exe"
Function CloseAPP(Appname)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Process", , 48)
For Each objItem In colItems
If InStr(1,Ucase(objItem.Name),Appname) >= 1 Then
objItem.Terminate
End If
Next
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是终止进程的函数:
用法:
Here is the function to kill the process:
Usage:
问题出在以下行:
这里将
Win32_Process.Name
属性值转换为大写,但不将Appname
转换为大写。默认情况下,InStr
执行区分大小写的搜索,因此如果输入字符串相同但大小写不同,您将不会获得匹配项。要解决此问题,您也可以将
Appname
转换为大写:或者您可以使用
vbTextCompare
参数忽略字母大小写:但是,实际上根本不需要此检查,因为您可以将其直接合并到查询中:
The problem is in the following line:
Here you convert the
Win32_Process.Name
property value to uppercase, but don't convert theAppname
to uppercase. By default,InStr
performs a case-sensitive search, so if the input strings are the same but differ in case, you won't get a match.To fix the problem, you can convert
Appname
to uppercase as well:or you can use the
vbTextCompare
parameter to ignore the letter case:However, there's actually no need in this check at all as you can incorporate it directly in your query:
批处理脚本尝试下面的操作
使用 cmd 行中的
Try out below with batch script
from cmd line use