Taskkill.exe: don't throw an error if the process is not running

I'm running a Visual Studio post build event that shuts down IIS if it's still running after compilation:

taskkill /f /im w3wp.exe

The following works perfectly if IIS is still running, but throws an error if it has already stopped:

Error 1 The process "w3wp.exe" not found. xxx\EXEC

Is there a way to tell taskkill to ignore the problem if it can't find a matching running process?


Instead of running one command, would running a small batch file work instead?

tasklist /FI "IMAGENAME eq w3wp.exe" 2>NUL | find /I /N "w3wp.exe">NUL
if "%ERRORLEVEL%"=="0" taskkill /f /im w3wp.exe

The solution I found to this was to run

START /wait taskkill /f /im w3wp.exe

It returns a success from the START command, and any error thrown by TASKKILL is thrown in the new console window


This works well too:

taskkill /IM "w3wp.exe" /F /FI "STATUS eq RUNNING"