Terminate multiple programs from the command line with Taskkill
Not all program termination options work all the time. If a program is not responding, you may not be able to use the window close button to terminate it. The same may be true for killing the process in the Windows Task Manager.
Taskkill is a versatile command line tool that you can use for these purposes. Among the many features that it supports is an option to close programs forcefully and to terminate multiple programs in a single operation.
Especially the latter can be useful if you need to clear rogue programs on your system that spawn new processes as soon as you terminate them.
The basic command is taskkill followed by parameters. A good starting point is to run taskkill /? to display the help text listing all parameters that you can use.
To terminate a process, you can use the following two core options:
- taskkill /IM explorer.exe
- taskkill /PID 1516
The first refers to the image name of the program running which you get when you run tasklist on the command line or by using the Windows Task Manager. The second the process ID of the process which you get in the same way.
Using the image name will kill all processes of that name. The process ID on the other hand allows you to select a specific process instead.
To terminate multiple processes at once use the following command.
- taskkill /PID 123 /PID 234 /PID 345
The parameter /f specifies that the selected processes should be terminated forcefully while /t that all of its child processes should be terminated along with it.
What makes taskkill particularly powerful is its filtering system. You can use filters to terminate matching processes to kill a whole batch of them at the same time.
Filters use the /fi parameter followed by instructions what you want to filter. The operators used here are:
- eq equal
- ne not equal
- gt greater than
- lt less than
- ge greater or equal
- le lesser or equal
Interesting filter names are IMAGENAME, CPUTIME, MEMUSAGE or USERNAME among others (see screenshot above for all of them and the operators they support).
As you can see, wildcards are supported. You can only use wildcards for /IM when at least one filter is specified.
Some examples:
- taskkill /FI "STATUS eq NOT RESPONDING"
- taskkill /FI "USERNAME eq MARTIN"
- taskkill /s servername /FI "IMAGENAME eq rog*" /im *
What they do
- Terminates all running processes with the status not responding
- Terminates all running processes by the user MARTIN
- Terminates all image names starting with rog on the server servername
You use the parameters /p and /u to set a password and username if necessary. The user parameter comes in the form Domain\User e.g. /u coredomain\martin /p secretpassword
Additional information are provided on Microsoft's Technet website
God tip, or can download my application to close any process by name or multiples process that match by name, example resetapp.exe -close “excel” -issequence true close all open excel process (multiple session of the program) http://marjuanm.blogspot.mx/2015/04/resetapp-reiniciando-o-cerrando.html
I do this with Autohotkey, and assign various kills to hotkeys. It’s a good way to avoid “are you sure you want to close this?” nags
A question: In the image illustrating /?, the expression FI appears in the 4th and 5th examples. FI is not explained in the text or image, so I was hoping you or a fellow reader would explain it to me. I’m sorry if I am being dense!
A remark: The neat little program ‘close all’ does close all running programs provided nothing malicious is going on and is pretty handy: http://www.ntwind.com/software/utilities/close-all.html
/FI is the filter argument and what follows specifies that filter.