I have a batch file which is launching a script (python one). I'm looking for a windows command which will terminate the script. taskkill is working in processes and there is no unique process here, so i'm looking for some command which will simulate right clicking the task and choosing "end task".

here is the task as shown in windows's task manager.

enter image description here


  • 2
    You could filter tasks by their window title, e.g. taskkill /fi "windowtitle eq C:\Windows\system32\cmd.exe - SAM" (titles are not case-sensitive). – and31415 May 4 '14 at 15:36

Yes there is, its cmd.exe taskkill can kill cmd.exe for you. If you need to be able to terminate it using a custom name, start the script using the start command, which allows you to give your program a unique title.

Lets assume you used MyApp Test as title by starting your script as follows:

start "MyApp Test" c:\python.py

Now you can kill your script using:

taskkill /f /FI "WINDOWTITLE eq MyApp Test"

Alternatively, but a bit risky, you probably can kill the task directly using the following command:

taskkill /f /FI "WINDOWTITLE eq *cmd.exe - SAM"

EDIT: As and31415 points out, the /f switch is not necessarily needed. It is used to force killing a task. This means that if a python script is no longer responding, the /f will still kill it, while without /f it might not. Try without and if it works, decide if you want to forcefully kill it or not.

| improve this answer | |
  • 1
    A few remarks: 1. Windows titles aren't case-sensitive, and 2. If you want to replicate the End Task button behavior you should omit the /f paramater (force kill). Unless you really want to kill it, that is. Further reading: technet.microsoft.com/en-us/library/cc725602.aspx – and31415 May 4 '14 at 16:08
  • @and31415 thanks. I added your /f comment to the solution. As for title not being case sensitive, I did write it with case sensitive in mind just because it looks so much better in the answer, and it doesn't really matter. – LPChip May 4 '14 at 16:57
  • You're welcome. I do agree it looks aesthetically better that way. Anyway, choosing a custom title only works with command-line based programs. For example, this won't have any effect: start "Some title" calc.exe – and31415 May 4 '14 at 17:46
  • Hi, when trying taskkill /f /FI "WINDOWTITLE eq *.SAM" I get: ERROR: The search filter cannot be recognized. – omer bach May 4 '14 at 18:24
  • Yeah, because your title is not ??????.SAM. There's no . Try * - SAM instead. – LPChip May 4 '14 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.