taskkill is a built-in Windows command-line utility that terminates one or more running processes, identified by process ID (PID) or image name, on the local computer or on a remote system. It is the standard way in the Windows Command Prompt to stop a hung application, clean up after a failed script or end a runaway service process without opening Task Manager.
Within PowerShell & command line administration, taskkill is the natural partner of tasklist, which lists processes, and the older counterpart of the PowerShell cmdlet Stop-Process. It supports filters, process trees and forced termination, which makes it powerful but also easy to misuse.
How taskkill ends a process
taskkill ends a process either by asking it to close or by forcing immediate termination, and the difference determines whether the application can save its state. Without the /F switch, taskkill sends a close request, which for windowed programs means a WM_CLOSE message to their top-level windows; the program may save data, prompt the user or ignore the request.
With /F, taskkill calls the system’s TerminateProcess function. The process stops at once, its threads end, and the kernel releases its handles and memory, but no cleanup code in the application runs. Unsaved documents are lost, temporary files may remain and databases may need recovery. Console applications and background processes have no window to close, so taskkill typically reports that they can only be terminated forcefully.
The table below compares the two termination modes.
| Mode | Mechanism | Application can save data | Typical use |
|---|---|---|---|
| Graceful (default) | Close request to the process windows | Yes, if it responds | Normal shutdown of desktop programs |
| Forced (/F) | TerminateProcess system call | No | Hung programs and console processes |
| Tree (/T) | Applies the chosen mode to child processes too | Depends on /F | Stopping a launcher and its workers |
Syntax and key switches of taskkill
The general form is taskkill [/S system [/U user [/P password]]] {[/FI filter] [/PID id | /IM name]} [/T] [/F], and at least one target must be specified through a PID, an image name or a filter. Switches can be combined and repeated, for example several /PID values in one command.
The most important switches are summarized in the next table.
| Switch | Meaning | Example |
|---|---|---|
| /PID | Target a process by its numeric ID | taskkill /PID 4312 |
| /IM | Target by image name, wildcards allowed | taskkill /IM notepad.exe |
| /F | Force termination | taskkill /F /IM chrome.exe |
| /T | Include all child processes | taskkill /T /PID 880 |
| /FI | Apply a filter expression | taskkill /FI "STATUS eq NOT RESPONDING" |
| /S, /U, /P | Remote computer and credentials | taskkill /S srv01 /IM app.exe |
Filters use operators such as eq, ne, gt and lt on fields like STATUS, USERNAME, MEMUSAGE, CPUTIME, WINDOWTITLE, MODULES and SERVICES. A filter such as MEMUSAGE gt 500000 targets processes using more than about 500 MB of memory, since the value is given in kilobytes. Wildcards with /IM accept a trailing asterisk, so /IM app* matches every image name beginning with app.
taskkill returns an exit code of 0 on success and a non-zero code when it fails, for example 128 when no matching process exists. Batch files can test this with if errorlevel to decide whether to continue.
taskkill compared with related tools
taskkill is one of several ways to stop processes on Windows, and the choice depends on the shell, the need for objects and remote access. The comparison below covers the common alternatives.
| Tool | Interface | Strength | Limitation |
|---|---|---|---|
| taskkill | Command Prompt and batch files | Filters, trees, remote targets | Text output only |
| Stop-Process | PowerShell cmdlet | Works with process objects in pipelines | No built-in tree option |
| Task Manager | Graphical interface | Visual overview and End task button | Not scriptable |
| WMIC process delete | Legacy command line | WMI-based remote control | Deprecated and being removed |
| sc stop | Service Control Manager | Clean stop of Windows services | Services only, not arbitrary processes |
For services, stopping through the Service Control Manager is preferred, because it lets the service shut down in an orderly way and keeps the service state consistent. taskkill with the SERVICES filter is a fallback when a service process will not respond.
Permissions, protected processes and failure cases
taskkill can only end processes that the caller has rights to terminate. A standard user can stop their own processes, while processes of other users, services running as SYSTEM and elevated programs require an elevated Command Prompt.
Some processes cannot be terminated at all from user mode. Critical system processes such as csrss.exe, protected processes like the Microsoft Defender service, and anti-malware processes running as protected process light return access denied even for administrators. Ending a critical process that is not protected can cause an immediate system crash.
| Message or symptom | Likely cause | Fix |
|---|---|---|
| Access is denied | Insufficient rights or protected process | Run elevated, or stop the owning service properly |
| Process not found | Wrong PID or image name | Check with tasklist first |
| Can only be terminated forcefully | Console or background process | Add /F after checking the impact |
| Process restarts immediately | A service or watchdog relaunches it | Stop or disable the parent service |
| RPC server unavailable | Remote firewall or service blocked | Allow remote management or use PowerShell remoting |
Safe practices for scripts and administration
Reliable use of taskkill starts with identifying the exact target before terminating it. Running tasklist with the same filter first shows what would be affected and prevents accidental termination of unrelated processes.
- Prefer PID over image name when several instances run and only one is faulty.
- Try a graceful close first and add
/Fonly after a timeout. - Use /T deliberately, because killing a parent shell can end unrelated child programs.
- Avoid broad wildcards in scheduled tasks, where nobody reviews the matches.
- Log exit codes in batch files so failed terminations are visible.
The simple explanation
taskkill is a typed command for closing programs. Instead of opening Task Manager and clicking End task, a person or a script writes the name or number of the program, and Windows closes it.
It can ask politely, giving the program a chance to save its work, or it can pull the plug immediately. The second option is useful when a program is frozen, but anything not saved is lost, so it is best used only when a normal close fails.
How it is used in practice
A help desk technician at a school supports 40 classroom computers. Every morning, a reporting tool occasionally freezes during startup and blocks a nightly batch job. The technician adds a step to the batch file that runs taskkill /FI "STATUS eq NOT RESPONDING" /IM report.exe, waits 30 seconds, then repeats the command with /F if the exit code shows the process is still running.
The script also writes the exit code to a log file. Over the next month, the frozen tool is closed automatically on nine occasions, the batch job completes every night, and the technician no longer needs to connect to each computer manually. The log shows that graceful closing worked in most cases, so data loss is avoided.