Tuesday, November 17, 2009

Killing tasks/processes from the command line in Windows 7

Sometimes you quickly need to kill a task in Windows (mostly from the command line). With Windows 7 this can be done by using the taskkill command. First thing you need to do is start a command line with administrative priviledges:

Type in command in the start menu, when the Command Prompt shows up, right click and select Run as Administrator.


 


After a warning message (if UAC is turned on), the command line is shown. Before we kill something, we need to know what we would like to kill :). This can be done by issuing a tasklist command.



The tasklist command will show all the running tasks (similar to task manager). This list can be quite long depending on your system. You can quickly filter by issuing the /M switch, eg.

taskkill /M vm*

will show all tasks (and modules) starting with vm in the name

Now killing the task is the easy part. Just issue a taskkill /IM with the name of the task:



The /IM specifies that we are using the image name and the /F at the end is used to specify we would like to kill the process forcefully. You can also kill a task by PID (process id) by using the /PID instead of /IM. It also allows you to kill multiple tasks eg:

taskkill /PID 230 349 230 /F

will kill processes 230, 349 and 230 simultaneously. The taskkill has much more functionality, eg killing multiple task based on filters, for example:

taskkill /IM note* /FI "windowtitle eq untitle*"
 

will kill every task name starting with note (eg notepad) and where the title starts with untitle, with other word kill all instances of empty notepad.

Enjoy!




No comments: