3

How to kill a task based on the path of the executable?

The usage of taskkill /F /IM "app.exe" doesn't work in this case because there are other programs running that have the same image/process/file name, but are totally different executables. The paths are different and the .exe files with same file name are different, too.

Something like "taskkill /F /IM "C:\path\to\exe\app.exe" would be ideal.

Mofi
  • 42,677
  • 15
  • 72
  • 128
Bigbob556677
  • 1,563
  • 1
  • 10
  • 30
  • 3
    You can use `WMIC` to get that information: `wmic process where "name='myprogram.exe'" get ProcessID, ExecutablePath` – Squashman Jun 11 '18 at 19:44
  • 1
    Does this answer your question? [taskkill to differentiate 2 images by path](https://stackoverflow.com/questions/13524303/taskkill-to-differentiate-2-images-by-path) – user May 12 '20 at 14:47

1 Answers1

6

Using WMIC, as suggested in the comments by Squashman, you can do it as a single command:

WMIC Process Where "ExecutablePath='C:\\path\\to\\exe\\app.exe'" Call Terminate
Compo
  • 34,184
  • 4
  • 22
  • 36