如何使用批处理文件杀死特定的VBScript?

时间:2018-09-20 10:31:45

标签: windows batch-file

如何使用批处理文件杀死特定的VBScript?

@echo off
set vbs="%temp%\dummy.vbs"

for /f "usebackq tokens=2" %%s in (`WMIC path Win32_Process where 'name="wscript.exe"' get commandline,processid | findstr /i /c:"%vbs%"`) do (
    taskkill /f /fi "pid eq %%s"
)

我也尝试了下面的代码,但是类似的命令行无法正常工作。

WMIC path Win32_Process where "name='wscript.exe' and commandline like %vbs%" get processid

谢谢!

1 个答案:

答案 0 :(得分:1)

在注释中包含项目,并使用 ^ 转义特殊字符。

@echo off

set "vbs=%temp%\dummy.vbs"

for /f "usebackq tokens=3" %%s in (
    `WMIC process where "name='wscript.exe'" get commandline^,processid ^| findstr /i /c:"%%vbs%%"`
) do (
    taskkill /f /fi "pid eq %%s"
)