Any way to write a Windows .bat file to kill processes?

PerformanceBatch FileProcess

Performance Problem Overview


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?

Performance Solutions


Solution 1 - Performance

You can do this with 'taskkill'. With the /IM parameter, you can specify image names.

Example:

taskkill /im somecorporateprocess.exe

You can also do this to 'force' kill:

Example:

taskkill /f /im somecorporateprocess.exe

Just add one line per process you want to kill, save it as a .bat file, and add in your startup directory. Problem solved!

If this is a legacy system, PsKill will do the same.

Solution 2 - Performance

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

Solution 3 - Performance

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).

Solution 4 - Performance

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.

Solution 5 - Performance

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.

Solution 6 - Performance

Download PSKill. Write a batch file that calls it for each process you want dead, passing in the name of the process for each.

Solution 7 - Performance

Use Powershell! Built in cmdlets for managing processes. Examples here (hard way), here(built in) and here (more).

Solution 8 - Performance

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"

Solution 9 - Performance

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 PIDs 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncodeLesView Question on Stackoverflow
Solution 1 - PerformanceFactor MysticView Answer on Stackoverflow
Solution 2 - PerformanceDevelopingChrisView Answer on Stackoverflow
Solution 3 - PerformancenpocmakaView Answer on Stackoverflow
Solution 4 - PerformanceJason ZView Answer on Stackoverflow
Solution 5 - PerformanceBrian StewartView Answer on Stackoverflow
Solution 6 - PerformanceShog9View Answer on Stackoverflow
Solution 7 - PerformanceslipsecView Answer on Stackoverflow
Solution 8 - PerformanceSarath KSView Answer on Stackoverflow
Solution 9 - PerformanceEduard FlorinescuView Answer on Stackoverflow