简体   繁体   English

如何在wmic进程的like子句中传递变量?

[英]How to pass variable in like clause of wmic process?

I am writing a batch file to kill a process whose commandline arg matches my search criteria In my batch file: 我正在编写一个批处理文件,以杀死其命令行arg与我的搜索条件相匹配的进程。

1) I will take an input from user : 1)我将接受用户的输入:

 set /p process=Process to Kill:

2) Now I will kill all process whose command line matches this parameter 2)现在,我将杀死所有命令行与此参数匹配的进程

WMIC PROCESS WHERE "COMMANDLINE LIKE '%%process%%'" call terminate

But this is not working. 但这是行不通的。 By working I mean the matching for like is being performed for %process% and not for the value of the process. 通过工作,我的意思是针对%process%而不是针对流程的值执行类似的匹配。

So how can I pass the variable in the like clause of CommandLine 那么如何在CommandLine的like子句中传递变量

This example is specific to use from a batch file: 此示例专门用于批处理文件:

@Echo Off

:GetProcess
Set "_process="
Set /P "_process=Process to Kill: "
If Not Defined _process GoTo GetProcess

WMIC Process Where "CommandLine Like '%%%_process%%%'" Call Terminate >Nul 2>&1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM