Taskkill.exe: don't throw an error if the process is not running
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"