Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 18 down vote accepted

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
share|improve this answer
perfect, thanks! – Luk Jan 13 '11 at 14:38

The solution I found to this was to run

START 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

share|improve this answer
and if you want to wait for tasks to be killed before continuing with the batch file. simply add: START /wait taskkill /f /im w3wp.exe – jezternz Jan 20 at 23:04

Or, this will just return an info message if not found:

taskkill /f /im w3wp.exe /fi "memusage gt 2"

Info from: here

share|improve this answer

This works well too:

taskkill /IM "w3wp.exe" /F /FI "STATUS eq RUNNING"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.