How to end a task from a batch file which is not a process?

Posted on


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



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"

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"

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.

Leave a Reply

Your email address will not be published.