Pass PID from task list and kill processes using task list

I am trying to get windows processes matching some specific criteria, for example. they look like "123456.exe" and try to kill them using the task list. I am trying to do it like this:

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

what's wrong and I don't know why ... Can someone give me a hint? Thanx in advance!

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

A few changes:

  • The command_to_process command requires quotation marks (``) on both sides of the command.
  • Pipes ("|") inside command_to_process must be escaped with a caret ("^").
  • findstr , ".exe". , "myapp4.exe" . , , , .
  • "skip = 2" , findstr, . - , , .

, script, "%% i" "% i" , , i was unexpected at this time.

+11

, . /FI taskkill

taskkill /FI "IMAGENAME eq your_image_name_here.exe"

== > taskkill

+1

All Articles