6.3. Killing a Process


You want to terminate a process. Even though Windows has come a long way in the past 10 years, the operating system can't prevent buggy or poorly written applications from becoming unresponsive.


Using a graphical user interface

  1. Open the Windows Task Manager (taskmgr.exe).

  2. Click on the Processes tab.

  3. If you do not see the process you want to set, be sure the box beside Show processes from all users is checked.

  4. Right-click on the target process, select End Process, and select the desired priority.


You can also accomplish the same task using the Sysinternals Process Explorer (procexp.exe) tool by right-clicking the process and selecting Kill Process.

Using a command-line interface

The following command kills a process by PID:

> taskkill -pid <PID>

And this command kills a process by name on a remote server:

> taskkill /s <ServerName> -im <ProcessName>

Use the /f option to forcefully kill the process.

The pskill.exe utility works in a very similar manner. Here are two examples:

> pskill <PID>
> pskill \\<ServerName> 

Using VBScript

' This code terminates the specified process. ' ------ SCRIPT CONFIGURATION ------ intPID = 2560 ' PID of the process to terminate strComputer = "." ' ------ END CONFIGURATION --------- WScript.Echo "Process PID: " & intPID set objWMIProcess = GetObject("winmgmts:\\" & strComputer & _ "\root\cimv2:Win32_Process.Handle='" & intPID & "'") WScript.Echo "Process name: " & objWMIProcess.Name intRC = objWMIProcess.Terminate( ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.