I want to kill all processes with taskkill by username, with this command:
taskkill /f /fi "USERNAME eq %username%"
The problem is that I want to exclude (skip) some processes (not kill them all), such as explorer.exe, taskmgr.exe, cmd.exe, and of course current CMD instance
How can i exclude this processes with taskkill?
thanks
asked Sep 29, 2016 at 16:55
BrianCBrianC
1851 gold badge3 silver badges10 bronze badges
3
Windows Native Batch Script CMD Method
Below is a batch script solution that uses Tasklist and FOR /F loops setting and parsing variables accordingly to get just the process names of the processes running of a specific user.
With Findstr these results are then parsed further to exclude any specified exclusions you set in the Exclusions
variable up top.
It’ll take the final remaining results and kill those process names for that specific username giving you the desired results via a batch script just as explained.
Batch Script
There are only two variables to set for this to work which are the Username
and the Exclusions
, and the rest will just work and do the rest of the process as you need. Just specific the full process names separated by a space one next to the other just as in the below script.
@ECHO ON
SET Username=user
SET Exclusions=explorer.exe taskmgr.exe cmd.exe
SET tmpfl=%temp%%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
GOTO :EOF
Batch Script 2
@ECHO ON
CD /D "%~DP0"
SET Exclusions=cmd.exe explorer.exe taskmgr.exe
SET tmpfl=%~n0tmp.dat
IF EXIST "%tmpfl%" DEL /F /Q "%tmpfl%"
SET Exclusions=%Exclusions% taskkill.exe
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "DELIMS=: TOKENS=2" %%A IN ('TASKLIST /FI "USERNAME EQ %Username%" /FO LIST ^| FIND /I "Image name:"') DO (
SET var=%%~A
SET var=!var: =!
ECHO !var! | FINDSTR /I /V "%Exclusions%">>"%tmpfl%"
)
FOR /F "USEBACKQ TOKENS=*" %%A IN ("%tmpfl%") DO (
TASKKILL /F /FI "USERNAME eq %Username%" /IM %%~A
)
DEL /F /Q "%tmpfl%"
GOTO :EOF
Further Resources
- EnableDelayedExpansion
- FOR /F
- Variable Substring
- Tasklist
- Find
- Findstr
- Taskkill
answered Sep 29, 2016 at 19:26
10
I would personally do this by using powershell.
Something like this:
$processes = Get-Process -IncludeUserName | where {$_.UserName -like "*USERNAME*"}
$tobeignored = @("explorer","Taskmgr","cmd")
foreach($process in $processes)
{
if($tobeignored.Contains($process.ProcessName))
{
continue;
}
else
{
Stop-Process $process.Id -Force
}
}
I have not been able to test run this, I kinda dont wanna kill my own processes Let me know if it (doesn’t) work(s)
answered Sep 29, 2016 at 17:42
KageKage
3571 silver badge9 bronze badges
4
You can do this by specifying multiple filters for taskkill
. For example, if you want to exclude explorer.exe, add a filter for the image name not being equal to explorer.exe (with the ne
operator):
taskkill /f /fi "USERNAME eq %username%" /fi "IMAGENAME ne explorer.exe"
answered Dec 14, 2018 at 17:23
edited I was not able to get the following code work on my XP (the documentation says it should work, maybe it is my computer), but in windows 7 it works without problems
taskkill /im arma2oaserver.exe /fi "username eq TCAGame_Svc50" /f
original answer More verbose, but worked for me on XP
@echo off
setlocal enableextensions disabledelayedexpansion
set "executable=arma2oaserver.exe"
set "user=TCAGame_Svc50"
for /f "tokens=2 delims=," %%a in ('
tasklist /fi "imagename eq %executable%" /v /fo:csv /nh 2^>nul
^| find /i "%user%"
') do taskkill /pid %%~a /f
tasklist will retrieve the list of processes based on executable name (/fi
), in csv format (/fo:csv
), without headers (/nh
) and in verbose mode (v
) to include the user name. The list of processes is filtered via a find
command to only retrieve the list of processes for the desired user. The resulting list is handled via a for
command that will use the commas as delimiters and for each of the records, the second field (the processID) will be retrieved. The taskkill
will terminate the processes using the pid retrieved.
PID (Process ID) is a short form for process identifier. A PID is a unique number that identifies each running process in an operating system, such as Linux, Unix, macOS, and Microsoft Windows. Task Killer can help you to kill (close or stop) the running apps of your device by ending one or more tasks or processes. Processes can be ended by PID or image name and Taskkill has replaced the kill tool.
Note: In order to kill a process via the Command Prompt or PowerShell, you need an Administrator (elevated) privilege.
As an Administrator from time to time, you may need to kill a service which is problematic and stuck or start a service that has refused to start.
- Killing a service that is stuck or has refused to start will save you the time of restarting or rebooting a Server.
To have this done, you will need to search for the PID of the service. To determine the name of a service, this can be found in the following ways.
– From the “services.msc” window (Also from the Task Manager, You can also access the services tab).
– To determine the service PID, I will be using the “sc queryex” command to query the service name of the application.
– Also, launch Command Prompt with Administrators privilege and run tasklist to see all of the running processes.
Note: Since the list might be very long, you can use a pipe character with more command as shown below
tasklist | more
How (steps) for querying a service name
– Launch an elevated Command Prompt (CMD): use the following command below with the service name from the command prompt.
sc queryex servicename
Kill a service: To kill a service, launch the command prompt, the PID is paramount as this will be used to kill the service. See the images above on how to obtain the process ID (PID).
– Launch an elevated Command Prompt and
– Type the following command below to kill the service
taskkill /f /pid [PID]
Where [PID] is the value associated the service name as shown above.
Note: The /f flag is used to kill the process forcefully. Failure to use the /F flag will result in nothing happening in some cases
Alternatively, we can also use the Task Manager to kill a service. For more information on using the Task Manager, see https://techdirectarchive.com/2020/04/24/how-to-launch-windows-task-manager/
Note: Ensure absolute care is taken on what service you are killing though. If you kill a critical windows service you may end up forcing the machine to reboot on its own in order to have this it resolved.
Below are other filtering options variables and operators that can be used with “taskkill”.
Variables | Operators |
STATUS | eq (equals) |
IMAGENAME | ne (not equal) |
PID | gt (greater than) |
SESSION | lt (less than) |
CPUTIME | ge (greater than or equal) |
MEMUSAGE | le (less than or equal) |
MODULES | |
Services | |
WINDOWSTITLE |
These variables and operators can be used with the /FI filtering flag.
– Example 1: You wish to end all processes that has a window title that starts with “DriveBit”:
taskkill /FI "WINDOWTITLE eq DriveBit*" /F
– Example 2: Kill all the process running under a user account
taskkill /FI "USERNAME eq Administrator" /F
– Example 3: Kill a service running on a remote desktop (server)
taskkill /S AnsibleServer /U RemoteAccountName /P RemoteAccountPassword /IM chrome.exe /F
For other similar tools that can be used in place of Task Manager, see the the following articles. For Process Explorer (SysInternal Tools), see https://techdirectarchive.com/2020/03/07/process-explorer/
– How to use SysInternals Live Tools, see https://techdirectarchive.com/2020/02/09/how-to-use-sysinternals-live-tools/
– How to download and use Windows SysInternals tools locally, see https://techdirectarchive.com/2020/01/25/windows-sysinternals-tools-psexec-and-auto-logon/
– Process Explorer (Replace built-in Task Manager) https://techdirectarchive.com/2020/03/08/process-explorer-replace-built-in-task-manager/
Via PowerShell: Killing a process via PowerShell is somewhat similar to killing a process using CMD.
– You also need elevated (Admin rights) to have this done.
Launch PowerShell as an Administrator
– Type the command Get-Process to see the list of running processes as shown below
Get-Process
1: To kill a process by its name: Execute the following cmdlet as shown below.
- Stop-Process -Name "ProcessName" -Force
To kill a process by its PID, run the command as shown below.
Stop-Process -ID PID -Force
I hope you found this blog post helpful. If you have any questions, please let me know in the comment session.
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…
Computer programs or applications commonly have one or more processes that are executing to support the program. These processes are instances of the running application and may have one or many Operating System threads dedicated to receive computer resources. Each program thread may execute any portion of the process code depending on the program design. Unfortunately, some programs will have a process hang or freeze and will not allow the end user to kill the process from the Windows Task Manager. If you attempt to close a process by selecting the “End Task” menu option from the Task Manager and if fails to close, you can alternatively use the “Taskkill” Windows utility program to kill a process.
How to Kill Windows Processes Manually
Step 1 – Open the Windows Task Manager by depressing the “CTRL + ALT+DEL” keys simultaneously and selecting the “Start Task Manager” menu option.
Step 2 – Open the MS DOS prompt by selecting the “Start” and “Run” menu options. Enter “command” in the search text field followed by the “Enter” key.
Step 3 – Enter the following command at the DOS prompt followed by the “Enter” key to gracefully kill the computer process (allows you to save any unsaved work if possible):
Taskkill /IM myProgramFile.exe
Step 4 – Input the following command if the process will not close gracefully after completing step 3. Note that if you have multiple iterations of the process running on your computer, this option will automatically close all open iterations of the program.
Taskkill /f myProgramFile.exe
Step 5 – Kill a single instance of a process by determining the Process ID from the Task Manager and using this number with the TaskKill application. To determine the PID, select the “View” and “Select Columns” menu options on the Windows Task Manager. Check the “PID” check box and the associated identification numbers will be displayed. Enter the following command followed by the “Enter” key to kill the specific process ID:
Taskkill /PID 123
Step 6 – Kill all process associated with a user on the computer by entering the following command followed by the “enter” key.
Taskkill /F /FI “USERNAM eq Smith”
Taskill Parameter Options
processid – The PID that will be terminated by the TaskKill utility application.
Processname – The process name used by the TaskKill utility to close. Should not be used with the PID argument.
/SERVER:servername – This is the server that has the PID that needs to be killed. It is normally only used with the command when used on the LAN or network level.
/ID:sessionid – Kills processes that are hung in the given session ID. Not normally used on home computers.
/A – Kills all computer processes that are being run under all user sessions and must be invoked by a computer administrator.
/V – Displays relevant information about the actions being conducted.
Download PC Repair Tool to quickly find & fix Windows errors automatically
These tools will help you kill or terminate ALL running processes or open applications instantly with a click on Windows 11/10/8/7. Use them if you need to do it frequently. I too prefer to use one of these, rather than closing each app one at a time.
1] Use BAT file
Here is a batch file which determines all the processes started by the user and terminates all these processes. It kills only the processes started by the user. These processes include tray applications and background applications.
Using this batch file you can free up lots of RAM before starting any memory-intensive application like Games or Video Encoders. You don’t have to terminate each and every application to free up RAM.
This batch file cannot kill protected applications like that of AntiVirus and Firewall
To kill all running apps just download the kill.bat and double click on it.
2] Use KilleThem All tool
KillThemAll created by a Neowin user does the same thing but gives the user a chance to save his data. It leaves Explorer.exe open, however.
Read: How to kill multiple processes at once.
3] Use Tasklist & Taskview
See how you can kill Processes via Command Prompt using Tasklist & Taskview commands.
4] Use CloseAll tool
CloseAll is a freeware tool that helps you to close all running applications & windows instantly with one click.
Let us know if you know of any other tools.
How to kill a process instantly when a Program is Not Responding may also interest you.
Anand Khanse is the Admin of TheWindowsClub.com, a 10-year Microsoft MVP (2006-16) & a Windows Insider MVP (2016-2022). Please read the entire post & the comments first, create a System Restore Point before making any changes to your system & be careful about any 3rd-party offers while installing freeware.
by Ivan Jenic
Passionate about all elements related to Windows and combined with his innate curiosity, Ivan has delved deep into understanding this operating system, with a specialization in drivers and… read more
Updated on March 25, 2021
XINSTALL BY CLICKING THE DOWNLOAD FILE
This software will repair common computer errors, protect you from file loss, malware, hardware failure and optimize your PC for maximum performance. Fix PC issues and remove viruses now in 3 easy steps:
- Download Restoro PC Repair Tool that comes with Patented Technologies (patent available here).
- Click Start Scan to find Windows issues that could be causing PC problems.
- Click Repair All to fix issues affecting your computer’s security and performance
- Restoro has been downloaded by 0 readers this month.
If you have multiple windows running on your PC, then your system might become slow, and you may face some errors. In order to solve this, you need to kill all those tasks. In this tutorial, we’ll show you how to easily kill all the running tasks at once with just one click.
I know that first thing that comes to your mind when you’re in a situation like this is forceful restarting. But you definitely shouldn’t do that, because forcefully restarting your PC could damage your computer and its system files. So, forget about forceful restarting, and perform some of the following actions in this article.
How do I kill all processes in Windows 10?
- Kill processes in Command Prompt
- Kill unresponding processes in CMD
- How to end all processes in Task Manager at once
- Clean boot your computer
Solution 1: Kill processes in Command Prompt
If you think that Windows already has all you need to solve various problems, than you can try this solution. Command Prompt is very useful, and is one of the most powerful features of Windows, so killing a couple of unresponding processes should be a piece of cake for such a tool. To kill unresponding processes with the Command Prompt, do the following:
- Go to Search, type cmd and open Command Prompt
- In Command Prompt, enter the following line and press Enter
- taskkill /f /fi “status eq not responding”
This command should kill all processes recognized as unresponding, and you’ll be good to go.
- RELATED: Fix: Critical_process_died csrss.exe on Windows 10
Solution 2: Use CloseAll
If you prefer to use third-party software to solve problems, CloseAll is probably the best task-killing tool out there. It automatically closes all running processes, leaving you on Desktop. All you have to do is to open it and press OK, and that’s the whole philosophy.
Some users recommend you to pin it to taskbar, in order to have easy, instant access to it every time you need it. You can download CloseAll from its official website, for free.
Solution 3: How to end all processes in Task Manager at once
In newer Windows 10 versions, related processes are grouped under one common cluster. As a result, you can end all the processes gathered under the same cluster by right-clicking on the respective cluster and selecting End Task.
Solution 4: Clean boot your computer
Another method to kill unnecessary processes is to clean boot your computer. This method allows you to start Windows using only a minimal set of drivers and programs. Of course, you’ll need to restart your computer for this solution to take effect.
- Go to Start > type msconfig > hit Enter
- Go to System Configuration > click on the Services tab > check the Hide all Microsoft services check box > click Disable all.
- Go to the Startup tab > Open Task Manager.
- Select each startup item > click Disable
- Close Task Manager > restart the computer.
- RELATED: Fix: STATUS SYSTEM PROCESS TERMINATED error on Windows 10
How to end particular processes
Now, if you want to stop only particular processes, apps and programs, there’s a solution for that as well.
How to end all Internet Explorer processes?
If you want to stop all IE processes, you can use Command Prompt for this task. Simply open Command Prompt as an administrator, enter this command: taskkill /F /IM iexplore.exe and hit Enter.
How to end all Google Chrome processes?
Google Chrome processes may sometimes eat up much of your computer resources. To stop all Chrome processes, go to Settings > Show advanced settings… Now, you can uncheck the option ‘Continue running background apps when Google Chrome is closed’ to kill all Chrome processes.
How to end all background processes in Windows 10?
To to this, go to Settings > Privacy > Background apps > turn off the ‘Let apps run in the background’ toggle.
So, this is how you can end all the processes on Windows 10 or only a specific category of processes.
RELATED GUIDES TO CHECK OUT:
- View all running Windows processes with NoVirusThanks Process Lister
- Top 5 Troubleshooting Tools and Software for Windows 10
- How to schedule tasks in Windows 10
Still having issues? Fix them with this tool:
SPONSORED
If the advices above haven’t solved your issue, your PC may experience deeper Windows problems. We recommend downloading this PC Repair tool (rated Great on TrustPilot.com) to easily address them. After installation, simply click the Start Scan button and then press on Repair All.
Newsletter
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.