Every time I turn on my company-owned development machine, I have to kill 10+ processes using the Task Manager or any other process management app just to get decent performance out of my IDE. Yes, these are processes from programs that my company installs on my machine for security and compliance. What I'd like to do is have a .bat file or script of some kind with which I can kill the processes in question.
Does anybody know how to do this?
This question is related to
performance
batch-file
process
Please find the below logic where it works on the condition.
If we simply call taskkill /im applicationname.exe
, it will kill only if this process is running. If this process is not running, it will throw an error.
So as to check before takskill
is called, a check can be done to make sure execute taskkill
will be executed only if the process is running, so that it won't throw error.
tasklist /fi "imagename eq applicationname.exe" |find ":" > nul
if errorlevel 1 taskkill /f /im "applicationname.exe"
As TASKKILL might be unavailable on some Home/basic editions of windows here some alternatives:
TSKILL processName
or
TSKILL PID
Have on mind that processName
should not have the .exe
suffix and is limited to 18 characters.
Another option is WMIC
:
wmic Path win32_process Where "Caption Like 'MyProcess%.exe'" Call Terminate
wmic offer even more flexibility than taskkill with its SQL-like matchers .With wmic Path win32_process get
you can see the available fileds you can filter (and %
can be used as a wildcard).
Here I wrote an example command that you can paste in your cmd
command line prompt and is written for chrome.exe
.
FOR /F "tokens=2 delims= " %P IN ('tasklist /FO Table /M "chrome*" /NH') DO (TASKKILL /PID %P)
The for just takes all the PID
s listed on the below tasklist
command and executes TASKKILL /PID
on every PID
tasklist /FO Table /M "chrome*" /NH
If you use the for in a batch file just use %%P instead of %P
I'm assuming as a developer, you have some degree of administrative control over your machine. If so, from the command line, run msconfig.exe. You can remove many processes from even starting, thereby eliminating the need to kill them with the above mentioned solutions.
Download PSKill. Write a batch file that calls it for each process you want dead, passing in the name of the process for each.
Get Autoruns from Mark Russinovich, the Sysinternals guy that discovered the Sony Rootkit... Best software I've ever used for cleaning up things that get started automatically.
taskkill /f /im "devenv.exe"
this will forcibly kill the pid with the exe name "devenv.exe"
equivalent to -9 on the nix'y kill command
Use Powershell! Built in cmdlets for managing processes. Examples here (hard way), here(built in) and here (more).
Source: Stackoverflow.com