Windows批处理文件 - 如果TASKKILL窗口标题包含文本 [英] Windows Batch file - taskkill if window title contains text

查看:2242
本文介绍了Windows批处理文件 - 如果TASKKILL窗口标题包含文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要写一个简单的批处理文件来杀死包含窗口标题的某些文本的过程。现在我有:

I want to write a simple batch file to kill a process that contains certain text in the window title. Right now I have:

taskkill /fi "Windowtitle eq XXXX*" /im cmd.exe  

和的作品,但我想要做的是无论是在标题的开头和结尾使用通配符。因此,像:

And that works, except what I want to do is use the wildcard both at the beginning AND end of the title. So something like:

taskkill /fi "Windowtitle eq \*X*" /im cmd.exe  

但我尝试这样做,这是行不通的。是否有什么我失踪,或者这是不可能的?

But I tried this and it does not work. Is there something I'm missing or is this not possible?

推荐答案

没有,通配符不会在过滤器开始允许的。

No, wildcards are not allowed at the start of the filter.

for /f "tokens=2 delims=," %%a in ('
    tasklist /fi "imagename eq cmd.exe" /v /fo:csv /nh 
    ^| findstr /r /c:".*X[^,]*$"
') do taskkill /pid %%a

这将检索任务列表,在CSV和详细格式(包括窗口标题作为输出的最后一个字段)。

This will retrieve the list of tasks, in csv and verbose format (that will include window title as the last field in the output).

FINDSTR 过滤,用常规的前pression,将搜索指定的文本( X )的最后一个字段。

The list is filtered by findstr with a regular expression that will search the indicated text (the X) in the last field.

如果任何线路滤波器,匹配将记号化它,检索将在TASKKILL用来结束过程中的第二个字段(PID)。

If any line matches the filter, the for will tokenize it, retrieving the second field (the PID) that will be used in taskkill to end the process.

这篇关于Windows批处理文件 - 如果TASKKILL窗口标题包含文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆