How can I kill a process by name on Windows with API functions only?
MrLore
3,7192 gold badges26 silver badges36 bronze badges
asked Feb 1, 2011 at 12:34
1
In a cmd window you can use taskkill /F /im cmd.exe
to kill all cmd.exe programs.
The /T
flag tells taskkill to forcefully kill the processes, whereas
taskkill /im cmd.exe
gracefully shuts it down by sending a kill signal.
more information on taskkill can be found here
another great tool for terminating processes is wmic
answered Feb 17, 2017 at 11:04
rukaelinrukaelin
2182 silver badges12 bronze badges
If by kill you mean terminate with extreme prejudice,theres’s always TerminateProcess. I’d advise against using it if you can find another way (such as posting WM_CLOSE to the main window), because loaded DLLs don’t get unloaded properly when you call TerminateProcess, so used resources might not get released.
The real problem is how to get from a name to a process ID, this normally involves
EnumProcesses()
EnumProcessModules()
GetModuleFileNameEx()
GetModuleBaseName()
and comparing the resulting base module name against what you’re looking for. But there may be more than one instance of a module name executing on a system. How would you differentiate between instances in this circumstance?
answered Feb 1, 2011 at 12:37
Bob MooreBob Moore
6,7083 gold badges29 silver badges42 bronze badges
answered Feb 1, 2011 at 12:41
Kyle AlonsKyle Alons
6,8972 gold badges34 silver badges28 bronze badges
0
Contents
- 1 How to Kill a Process in Windows 10 with Task Manager
- 2 How to Kill a Process with the Taskkill Command
- 3 How to Terminate a Process with PowerShell
- 4 How to Identify the Process of any Open System Dialog or Program Window with Process Explorer
- 5 How to Kill Any Window-related Process Directly with just Two Clicks
For the most part, Windows 10 programs function just fine, but when one misbehaves it’s often necessary to kill its process. At times, apps can refuse to close, get stuck on a blank screen, or suddenly consume a lot of system resources. Terminating the task will force it to close and free up your system for normal functioning.
Identifying and killing a process of single windows and background apps
There are various ways to kill a process, but all of them make use of an application’s PID (Process ID), a unique identifier that ensures only the correct one is terminated. However, it’s worth noting that terminating a specific application process can still have knock-on effects on the rest of the program’s functions if they rely on it.
The most common way in Windows to terminate a process is through Task Manager. But today we’ll also be covering how to kill a process with PowerShell, how use the taskkill command in Command Prompt, how to find a process ID with Process Explorer (Microsofts ooptional advanced Task Manager) and using a two-click-method via a task bar button.
Different methods to kill a process for different needs
Some programs run several processes at once which means if you want to terminate the application completely you will have to kill all those processes. And there are cases where you will have a program window or system dialog but cannot identify the underlying process. In our tutorial you will find solutions for all of those issues.
How to Kill a Process in Windows 10 with Task Manager
Task Manager is the bread and butter of Windows 10 task killers, providing a simple interface with all the information users need to make informed decisions about which applications they should close. Accessing it is as easy as pressing “Ctrl + Shift + Esc”.
- View more details
After opening Task Manager with “Ctrl + Shift + Esc”, press the “More details” button in the bottom left to view more information.
- Select the process you want to kill and click “End task”
You can also press the “Delete” key instead to save some time.
- OR: Find an individual process and terminate it
Click the “Details” tab, find your process, and click “End Task” or press “Delete”.
How to Kill a Process with the Taskkill Command
If task manager isn’t an option because you’re using a Windows server install or it’s blocked by your administrator, you can achieve similar results through the use of the taskkill command in Command Prompt.
- Open Command Prompt
Press the Windows key and type “Command Prompt”, then choose “Run as administrator”.
- Run the tasklist command
You can get a quick readout of all the currently running processes, much like Task Manager, by typing
tasklist | more
and pressing “Enter” - Run the taskkill command to kill the process
Type
taskkill /F /PID x
, wherex
is replaced by your process’ PID. - OR: Use taskkill to kill a process by its name
If you know the name of the process’ .exe file, you can optionally use that to kill the task instead:
taskkill /IM "yourprocess.exe" /F
How to Terminate a Process with PowerShell
Alternatively, those familiar with PowerShell can use it kill tasks instead. This has the advantage of quite intuitive commands.
- Open PowerShell as an admin
Press “Windows + X” to open the fly-out menu, then click “Windows PowerShell (Administrator)”.
- Get a list of processes
In PowerShell, type
Get-Process
to have it return a list of all of the currently running processes on your PC and their PID. - Use PowerShell stop process to kill the task
To stop the process, type the following, substituting the x for the relevant PID:
Stop-Process -ID x -Force
- OR: Kill process by name in PowerShell
As with command prompt, you can also kill one or more processes at once in PowerShell by their name. This time, however, you’ll need its system name rather than its .exe file. For example:
Stop-Process -Name "YourPhone" -Force
How to Identify the Process of any Open System Dialog or Program Window with Process Explorer
As you’ve likely realized by now, scrolling through a giant list to get the name or PID of an application can be an annoyance. To remedy this, you can use Microsoft’s Process Explorer.
- Download Process Explorer
Head to Microsoft’s Process Explorer documentation and press the “Download Process Explorer” button to download the application.
- Run Process Explorer
Head to the folder you downloaded the application to and double-click “Procexp64.exe” or “proxexp.exe” depending on whether your system is 64 or 32-bit.
- Kill a process with Process Explorer
You can use Process Explorer much like Task manager by clicking the application and pressing the ‘x’ button in the top toolbar to stop it.
- Optional: Use the identification crosshair
Alternatively, if you don’t know the name of the application or its process, click the target button in the top toolbar.
- Drag the target to the process you want to identify
The process will then be automatically selected in the list and you can stop it as normal.
Though all of the above methods work just fine, if you find yourself having to kill tasks regularly they still aren’t ideal. For such use cases, we recommend Grizzly Bear’s “Kill”, a tiny 205KB app that you can pin to your taskbar to kill window process with two clicks.
- Download Kill
Go to the dcmembers site and download the Kill.exe freeware by pressing the big blue “Download” button.
- Pin Kill.exe to the taskbar
In the kill folder, right-click “Kill.exe” and select “Pin to taskbar”.
- Kill any window process with Kill.exe
To kill a process, simply click the button on your taskbar and then click on the application window.
If you found this tutorial helpful, you may also be interested in our guides about changing process affinity and OneDrive syncing any directory via mklink.
Contents
- Through the Command Prompt
- Via Task Manager
- Use CloseAll and other powerful tools
- Use PowerShell
- Here are particular steps to take:
- How to kill all the processes in Windows 11?
Multiple open and running windows on your desktop or laptop can lead the system to become slow and even face some errors. So you might wonder: can I stop all the processes running or kill all open applications in Windows 10?
Perhaps in seeking to terminate all running processes, the first thing you’re considering is forceful restarting. Forget about doing it – forceful restarting could lead to computer and system files damage. Instead, follow these methods on how to kill all the processes in Windows 10 properly:
Through the Command Prompt
Learn how to terminate Windows 10 processes in the Command Prompt, particularly unresponding ones. Do this through the following steps:
- Go to Search. Type cmd and open Command Prompt.
- Once there, enter this line taskkill /f /fi “status eq not responding” and then press Enter.
- This command should end all processes deemed unresponding
Via Task Manager
More recent Windows 10 versions have related processed bundled under a common cluster. End all the processes under a single cluster through right-clicking on that cluster and choosing End Task.
Freeware tool CloseAll is third-party software that automatically closes all running processes, leaving the user on Desktop. Simply open it and then press OK. KillThemAll, a creation of a Neowin user, also does the same task but gives users a chance to save their data. Take note, though, that it leaves Explorer.exe open.
Use PowerShell
Kill a process that runs elevated by opening PowerShell as Administrator. Type the command Get-Process for you to see the list of running processes. Kill a process by its name by executing this cmdlet: Stop-Process -Name “ProcessName” -Force. Kill a process by its PID by running this command: Stop-Process -ID PID -Force.
Clean boot your computer – This technique allows you to start Windows through only a minimal number of drivers and programs. However, you would need to restart your PC in order to get the desired effect. Here are some steps:
- Go to Start. Type msconfig and then hit Enter.
- Go to System Configuration. Once there, click on Services, check the Hide All Microsoft services check box, and then click Disable all.
- Go to Startup. Open Task Manager.
- Select every startup item and click Disable.
- Close Task Manager and then restart the computer.
How about if you want to end specific processes, programs, or apps in Windows 10?
Here are particular steps to take:
To end all background processes, go to Settings, Privacy, and then Background Apps. Turn off the Let apps run in the background
To end all Google Chrome processes, go to Settings and then Show advanced settings. Kill all related processes by unchecking Continue running background apps when Google Chrome is closed.
To end all Internet Explorer processes, use the Command Prompt as an administrator. Enter the command taskkill /F /IM iexplore.exe and then press Enter.
How to kill all the processes in Windows 11?
As you can see, stopping all processes on Windows 10 is pretty easy. But how can you do the same on Windows 11?
The new operating system comes with a number of improvements and upgrades. For instance, Windows 11 comes with a new design that features a centered Start menu and Taskbar. There is also a more Mac-like interface in place and lots of fixes for previously reported bugs.
With that, when it comes to quickly stopping all processes on the new OS, you can still use all the same methods as listed above for Windows 10. Namely:
You can stop all processes on Windows 11 via Command Prompt (see how to terminate Windows 11 processes via the Command Prompt above).
You can also stop all current running processes on Windows 11 via Task Manager, using CloseAll tool and PowerShell and, finally, by performing a clean boot of your PC.
Additionally, you can also set up a hotkey on your Windows 11 for terminating all unresponsive processes on your computer. Here’s how to do that:
- First, you will need to download the WinHotKey app via your web browser.
- After you have the WinHotKey app, open the program and follow the prompts of the WinHotKey setup wizard.
Once you have the app, you can assign a hotkey to a Task Kill desktop shortcut. Once you do that, you will be able to instantly terminate all unresponsive processes by simply using the Ctrl + Alt key combo whenever needed.
There you go – it’s fairly easy to learn how to kill all the processes in Windows 10/11 or just a specific group of processes. You can also tune up your computer for peak performance through using tools like Auslogics BoostSpeed, which effectively diagnoses your Windows system, cleans out junk files, restores system stability, and improves speed and performance.
Good luck and we hope you’ll have a smooth PC experience from here!
Do you like this post? 🙂
Please rate and share it and subscribe to our newsletter!
21 votes,
average: 3.43 out of
5
Loading…
Sometimes when an application in Windows hangs, freezes and stops responding the only way to terminate it is to kill from the command-line.
The taskkill
command in Windows serves for terminating tasks by name or by process id (PID).
In this note i am showing how to find and kill a process by its name or by PID and how to identify a process by the listening port.
I am also showing how to troubleshoot “The process could not be terminated” and “Access denied” errors.
Cool Tip: Get the return code from the last command or application! Read more →
List all Windows processes and find the full name of a process to kill (case insensitive):
C:> tasklist | findstr /I process_name
Kill the process by name:
C:> taskkill /IM process_name.exe
Kill Process by PID
List all Windows processes and find the PID of a process to kill (case insensitive):
C:> tasklist | findstr /I process_name
Kill the process by PID:
C:> taskkill /PID process_id
Kill Process by Port
List all Windows processes listening on TCP and UDP ports and find the PID of a process running on a specific port:
C:> netstat -ano | findstr :port
Find the name of a process by its PID:
C:> tasklist /FI "pid eq process_id"
Kill the process by name or by PID:
C:> taskkill /IM process_name.exe - or - C:> taskkill /PID process_id
Cool Tip: Windows grep
command equivalent in CMD and PowerShell! Read more →
Troubleshooting
Kill the process forcefully in case of the following error:
ERROR: The process with PID XXX could not be terminated.
Reason: This process can only be terminated forcefully (with /F option).
C:> taskkill /F /IM process_name.exe - or - C:> taskkill /F /PID process_id
If you get an “Access is denied” error, you should open the command prompt as an administrator:
ERROR: The process with PID XXX could not be terminated.
Reason: Access is denied
To run the CMD as an administrator, press ⊞ Win keybutton to open the start menu, type in cmd
to search for the command prompt and press Ctrl + Shift + Enter to launch it as administrator.
When you start an app, the operating system creates a process for an executable file of the app. It contains the program code and its current activity. Windows assigns a special number known as Process Identifier (PID) which is unique for every process. There are a number of reasons you might want to kill a process, and different methods you can use to terminate it. Here is how it can be done.
If an app stops responding, consumes a lot of system resources or behaves unexpectedly and doesn’t allow you to quit it, you might want to kill its process to forcefully close the app. Traditionally, Windows allowed using Task Manager and the command prompt for these tasks. In addition to these methods, you can use PowerShell. Here is how.
To kill a process in Windows 10, do the following.
- Open Task Manager.
- Click on «More details» in the bottom right corner to enter Full view mode.
- Select the desired app in the app list.
- Click on the End task button or hit the Del key on the keyboard.
You are done.
This is Task Manager’s most well known method.
Note: The same can be done from the Details tab. It is a special tab which lists process names instead of app names. There you can select a process in the list and either click on the End process button or hit the Del key.
Using the End Task button means Windows first tries to see for a certain timeout if the process has really stopped responding, and attempts to collect a crash or memory dump of the process. It then terminates the app.
Tip: We highly recommend you read the article How to end a process quickly with Task Manager in Windows 10 to learn all Task Manager tricks. Also, you can get the classic Task Manager app in Windows 10 to end processes or tasks.
Another classic method to close a process is the console tool taskill. It comes bundled with modern versions of Windows.
Kill a process using Taskkill
Note: Some processes are running as Administrator (elevated). In order to kill them, you need to open an elevated command prompt instance.
- Open the command prompt as the current user or as Administrator.
- Type tasklist to see the list of running processes and their PIDs. Since the list might be very long, you can use a pipe character with the more command.
tasklist | more
- To kill a process by its PID, type the command:
taskkill /F /PID pid_number
- To kill a process by its name, type the command
taskkill /IM "process name" /F
For example, to kill a process by its PID:
taskkill /F /PID 1242
To kill a process by its name:
taskkill /IM "notepad.exe" /F
Taskkill supports many useful options which you can use to terminate apps. You can learn them by running it as follows: taskkill /?
. Using taskkill, you can close all not responding tasks at once in Windows 10.
Kill a process using PowerShell
Note: To kill a process which runs elevated, you need to open PowerShell as Administrator.
- Open PowerShell. If required, run it as Administrator.
- Type the command
Get-Process
to see the list of running processes. - To kill a process by its name, execute the following cmdlet:
Stop-Process -Name "ProcessName" -Force
- To kill a process by its PID, run the command:
Stop-Process -ID PID -Force
Examples:
This command will close the notepad.exe process.
Stop-Process -Name "Notepad" -Force
The next command will close a process with PID 2137.
Stop-Process -ID 2137 -Force
If you need to kill a Store app, see the following article:
How to Terminate Store Apps in Windows 10
That’s it.
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won’t take a lot from you, but it will help us grow. Thanks for your support!
Everyone knows how to kill a process in Windows using Task Manager. However, when you’re on a Terminal Server Environment with 20 other users and you need to kill all matching processes on Windows from Command prompt it is just not possible because there might be 100 processes running. But hey, if you ask me, I would simply force disconnect all users using Task Manager but then I might get into trouble! Anywho, you can use tasklist
to list all Windows processes and taskkill
to kill all matching processes on Windows from command prompt, similar to kill
or kill -9
on Linux. The best part (knowing Windows and all, you can actually search and match filters while doing it; no … it doesn’t have grep
but similarish!)
All of this is possible with the TaskKill command. First, let’s cover the basics. You can kill a process by the process ID (PID
) or by image name (EXE
filename).
Open up an Administrative level Command Prompt and run tasklist
to see all of the running processes:
C:WINDOWSsystem32>tasklist Image Name PID Session Name Session# Mem Usage ========================= ======== ================ =========== ============ System Idle Process 0 Services 0 8 K System 4 Services 0 9,720 K Registry 120 Services 0 9,668 K smss.exe 444 Services 0 484 K csrss.exe 628 Services 0 2,004 K wininit.exe 732 Services 0 3,256 K services.exe 804 Services 0 7,584 K lsass.exe 824 Services 0 12,408 K svchost.exe 996 Services 0 344 K svchost.exe 96 Services 0 19,960 K fontdrvhost.exe 364 Services 0 768 K svchost.exe 928 Services 0 10,700 K svchost.exe 1040 Services 0 5,244 K svchost.exe 1296 Services 0 2,300 K svchost.exe 1304 Services 0 5,376 K
In the example above you can see the image name and the PID for each process. If you want to kill the firefox process run:
C:>Taskkill /IM firefox.exe /F
or
C:>Taskkill /PID 26356 /F
The /F
flag is kills the process forcefully. Failure to use the /F
flag will result in nothing happening in some cases. One example is whenever I want to kill the explorer.exe
process I have to use the /F
flag or else the process just does not terminate.
If you have multiple instances of an image open such as multiple firefox.exe
processes, running the taskkill /IM
firefox.exe
command will kill all instances. When you specify the PID
only the specific instance of firefox will be terminated.
The real power of taskkill
are the filtering options that allow you to use the following variables and operators.
Variables:
STATUS IMAGENAME PID SESSION CPUTIME MEMUSAGE USERNAME MODULES SERVICES WINDOWTITLE
Operators:
eq (equals) ne (not equal) gt (greater than) lt (less than) ge (greater than or equal) le (less than or equal) "*" is the wildcard.
You can use the variables and operators with the /FI filtering flag. For example, let’s say you want to end all processes that have a window title that starts with “Internet”:
C:>taskkill /FI "WINDOWTITLE eq Internet*" /F
How about killing all processes running under the Steve account:
C:>taskkill /FI “USERNAME eq Steve” /F
It is also possible to kill a process running on a remote computer with taskkill. Just run the following to kill notepad.exe on a remote computer called SteveDesktop:
C:>taskkill /S SteveDesktop /U RemoteAccountName /P RemoteAccountPassword /IM notepad.exe /F
To learn more about taskkill
run it with the /?
command just like any other Windows command.