Powershell – Excecute “taskkill /f /im chrome.exe” even when no chrome process is running

cmd, google-chrome, powershell

I execute this command

taskkill /f /im chrome.exe

In order to stop all chrome process and it works fine only when there is a chrome process running. Most of time I need to run the command even when there is no process of chrome running. How is it possible using command line?

PS: When I run the command and no chrome process is running I got an error like
chrome.exe not found

Best Solution

Actually the command does execute, as you would not get an error message otherwise.

Anyway, I suppose you basically want to suppress the error message, which can be accomplished by appending 2> nul to the command line (separated by a SPACE):

taskkill /f /im chrome.exe 2> nul

If you want to reset the exit code (ErrorLevel), write ver> nul into the next line (this works because ver is a command that never fails and resets the ErrorLevel value):

taskkill /f /im chrome.exever > nul

Or in a single line:

taskkill /f /im chrome.exe & ver > nul

Of course you may combine these two measures:

taskkill /f /im chrome.exe 2> nul & ver > nul