Fastest way to close a running executable in PowerShell is with Stop-Process (alias: kill). Stop-Process is a great tool for developers, especially when developing an application that sometimes doesn’t close properly, has stopped responding, are not shown on screen, or run multiple processes.

Stop-Process PowerShell

PowerShell 5 and newer can stop processes with Stop-Process (or alias kill) using the process name:

Stop-Process -Force -Name 'ProcessName'

For example, to close all instances of notepad.exe:

Stop-Process -Name "Notepad"

# or simply
kill -Name "Notepad"

Additionally, if the application is running in elevated mode (e.g., admin mode) or has stopped responding you will get an error such as:

Stop-Process: Cannot stop process "Notepad (5852)" because of the following error: Access is denied.

To fix this add -Force as an argument:

Stop-Process -Name "Notepad" -Force

This will force close all processes named “Notepad”. Note this is not the window name but the ProcessName that is found in Get-Process.

For example, list all processes with Get-Process:

Output:

> Get-Process

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName 
 ------    -----      -----     ------      --  -- -----------
...
    42    63.66      78.85       0.02   20524   1 Notepad   <- this is the name we want
...

Or we can close a specific process id (see above the Id):

Stop-Process -Id 20524

Or search for the process specificially:

Get-Process | FindStr /i "Notepad"

Output:

     41    63.34      78.27       0.02   20524   1 Notepad
     36    24.58      58.82       2.61   35508   1 notepad++

TASKKILL Command Prompt

In Command Prompt, the fastest way to close an executable is with TASKKILL.

The most simple is:

taskkill /IM <exe_name>

For example, taskkill /IM notepad.exe. This will close all tasks that are notepad.exe. Note if you are unsure about the task name (also known as: “image name” or “process name”) then call tasklist | findstr "notepad", this will list all tasks that have notepad in the name.

The task can also force quit with /F, e.g., taskkill /F /IM notepad.exe. Note that it will immediately close the app without any request to save dialog. Other commands can be listed with taskkill /?.

Wild cards can be useful to close multiple processes, e.g., taskkill /F /IM myapp* will force close any process that starts with “myapp”. This is useful to close related applications or an application that uses multiple-processes.

If you get an error such as the one below then run your command from an admin console.

ERROR: The process "notepad.exe" with PID 27096 could not be terminated.
Reason: Access is denied.

Also useful when Window’s shell (Explorer) freezes or gets into an unresponsive state. Just taskkill /F /IM explorer.exe then bring up the Task Manager (ctrl+shift+esc) or with ctrl+alt+del and run explorer.exe again.