taskkill - Terminate Processes
When an application freezes and stops responding, Task Manager is the usual way to close it. You can also end processes from the command prompt with the taskkill command.
It is especially useful when you automate tasks in batch files or want to close several processes at once.
If you just want to close a frozen app, run taskkill /F /IM appname.exe. You can look up the executable name with the tasklist command.
taskkill syntax
TASKKILL [options]
Main options
| Option | Description |
|---|---|
/IM process_name | Terminate by process (image) name |
/PID process_id | Terminate by process ID |
/F | Force termination |
/T | Also terminate child processes |
/FI "filter" | Target processes that match a filter |
Terminate by process name (/IM)
Specify the executable name to end a process.
taskkill /IM notepad.exe
If several processes share the same name, all of them are targeted. /IM also accepts the wildcard *.
taskkill /F /IM chrome*
Force termination (/F)
If the normal termination signal does not close the process, use /F to force it.
taskkill /F /IM notepad.exe

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超 入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
Without /F, a close request (WM_CLOSE) is sent to the process, and the application may show a dialog such as “Do you want to save?”. With /F, the process ends immediately without any dialog, so unsaved data is lost.
Terminate by process ID (/PID)
You can also use the process ID (PID) that you found with the tasklist command.
taskkill /PID 12345
Terminate several processes at once
taskkill /PID 12345 /PID 67890
To end only one of several processes with the same name, look up its PID with tasklist and pass it to /PID.
Terminate child processes too (/T)
The /T option ends the specified process together with its child processes.
taskkill /F /T /IM cmd.exe
Because /T also ends child processes, unintended processes may be terminated. When you target cmd.exe, take care not to close your own command prompt.
Use filters (/FI)
The /FI option limits the target to processes that match a condition.
Main filter conditions
| Filter | Operators | Description |
|---|---|---|
STATUS | eq, ne | Process status |
IMAGENAME | eq, ne | Process name |
PID | eq, ne, gt, lt, ge, le | Process ID |
MEMUSAGE | eq, ne, gt, lt, ge, le | Memory usage (KB) |
USERNAME | eq, ne | User running the process |
WINDOWTITLE | eq, ne | Window title |
Terminate unresponsive processes
taskkill /F /FI "STATUS eq NOT RESPONDING"
This targets only “not responding” processes, which is handy for closing frozen applications in bulk. The condition mainly works for applications with a window and may have no effect on background processes.
Terminate by window title
The WINDOWTITLE filter narrows the target by window title. Wildcards are supported.
taskkill /F /FI "WINDOWTITLE eq *Notepad*"
Find processes that use a lot of memory
tasklist /FI "MEMUSAGE gt 500000"
After checking, you can end the processes you need to. taskkill accepts the same /FI filters.
When a process will not close
”Access is denied”
To end another user’s process or a system-managed process, run the command prompt as administrator. Protected processes (such as security software) cannot be stopped with taskkill even then.
”The process was not found”
The process name is misspelled or the process has already ended. Check the correct image name with tasklist.
Check the result with the exit code
taskkill returns exit code 0 on success and 128 when the target process was not found, so a batch file can branch on ERRORLEVEL.
taskkill /F /IM notepad.exe >nul 2>&1
IF %ERRORLEVEL% EQU 0 (
echo Terminated.
) ELSE IF %ERRORLEVEL% EQU 128 (
echo The process was not found.
) ELSE (
echo Could not terminate it. Administrator rights may be required.
)
Terminate processes on a remote computer
Use /S for the computer name, /U for the user name and /P for the password to end processes on another PC on the network (permissions and firewall settings are required). Some filters, such as /FI "STATUS ...", cannot be used with remote processes.
taskkill /S PC-SERVER01 /U username /IM notepad.exe /F
Practical examples
Close several applications at once
@echo off
echo Closing browsers...
taskkill /F /IM chrome.exe >nul 2>&1
taskkill /F /IM msedge.exe >nul 2>&1
taskkill /F /IM firefox.exe >nul 2>&1
echo Done.
Safely end a process in a batch file
@echo off
setlocal
set TARGET=notepad.exe
tasklist /FI "IMAGENAME eq %TARGET%" | findstr /I "%TARGET%" >nul
IF %ERRORLEVEL% EQU 0 (
echo Closing %TARGET%.
taskkill /IM %TARGET%
) ELSE (
echo %TARGET% is not running.
)
endlocal
Using TASKLIST and TASKKILL together
The usual flow is to check a process with tasklist and then end it with taskkill.
tasklist /FI "IMAGENAME eq notepad.exe"
taskkill /IM notepad.exe
Summary
| Task | Command |
|---|---|
| End by process name | taskkill /IM name |
| Force termination | taskkill /F /IM name |
| End by PID | taskkill /PID id |
| End including child processes | taskkill /F /T /IM name |
| End unresponsive processes | taskkill /F /FI "STATUS eq NOT RESPONDING" |
| End a process on a remote PC | taskkill /S PC /U user /IM name /F |