从任务列表通过PID和杀死任务列表进程 [英] Pass PIDs from tasklist and kill processes with tasklist

查看:221
本文介绍了从任务列表通过PID和杀死任务列表进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Windows进程符合一定的条件,例如他们就像123456.exe,并试图与任务列表要杀死他们。我试图做这样的:

  FOR / F令牌有usebackq = 2跳过= 2%I IN(`任务列表| FINDSTR / R[0-9] .exe文件),DO的taskkill / PID%I

这是不正确的,我不知道为什么....谁能给我一个提示?
thanx提前!


解决方案

  FOR / F有usebackq令牌= 2%I IN(`任务列表^ | FINDSTR / R / B[ 0-9] [0-9] * [。] EXE`)DO TASKKILL / PID%I

若干变化:


  • 的command_to_process需要反引号(``)的命令的两侧。

  • 管道(|)的command_to_process内需要使用符号(^)进行转义

  • 您FINDSTR命令将会匹配面前有名为.exe数字的所有进程。例如,myapp4.exe也将被杀害。我会提供完全匹配包含数字的进程名的版本。

  • 跳过= 2选项会跳过从FINDSTR前两行输出,而不是任务列表。由于从任务列表输出前两行的常规前pression将不匹配任何东西,你可以安全移除跳过选项。

顺便说一句,如果你在一个批处理脚本把这个命令,记得用%%我而不是%I为您的参数,或者你会得到像的错误信息我是出乎意料的在这个时候。

I am trying to get windows processes matching some certain criteria, e.g. they are like "123456.exe" and trying to kill them with tasklist. I am trying to do it like that:

FOR /F "usebackq tokens=2 skip=2" %i IN (`tasklist |findstr /r "[0-9].exe") DO taskkill /PID %i

which is not right and I don't know why.... Can anyone give me a hint? Thanx in advance!

解决方案

FOR /F "usebackq tokens=2" %i IN (`tasklist ^| findstr /r /b "[0-9][0-9]*[.]exe"`) DO taskkill /pid %i

Several changes:

  • The command_to_process needs back quotes (``) on both sides of the command.
  • Pipes ("|") inside of the command_to_process need to be escaped with a caret ("^").
  • Your findstr command would match all processes that have a digit before the ".exe". For example, "myapp4.exe" would also have been killed. The version I provide will match process names solely containing numbers.
  • The "skip=2" option would skip the first two lines output from findstr, not tasklist. Since the regular expression won't match anything in the first two lines output from tasklist, you're safe to remove the skip option.

By the way, if you place this command in a batch script, remember to use "%%i" instead of "%i" for your parameters, or you'll get an error message like i was unexpected at this time.

这篇关于从任务列表通过PID和杀死任务列表进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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