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
Best Answer
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 theExclusions
, 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.Batch Script 2
Further Resources