Automatically restart Windows service if it is not running

I have a windows service running on a Windows 2003 server. Under the properties option when you right click the service, there is an option to restart the service if it fails. The options available are for the first, second and any subsequent failures.

I tried to use this option to restart the service when not running but it looks like it only restarts the service if the service fails as a result of a failure. The problem i have is that if there is a failure, the service picks this up and shuts down the service 'gracefully'. This means it is not being restarted.

Is there a way i can restart the service regardless of whether it stopped because of a failure or if it stopped gracefullly?

Thanks


For a misbehaving service like that, I'd create a small script that checks if it's running and starts it if it isn't. Then I'd use scheduled tasks to run the script every 5 minutes or so.

Example script (checks for the spooler service):

@echo off
Rem Look for the Print Spooler service in the list of started services
net start | find /i "Print Spooler"
Rem if not found, start it and a restart occurred.
if "%errorlevel%"=="1" (
   echo Service "Print Spooler" restarted at %time% on %date% by Script %0>>c:\ServiceRestart.Log
   net start "Print Spooler"
)

What service is it? I had a weird issue with the MS Fax service once. I resolved it by checking processes under Task Manager, ending the process if it is listed, then opening a Command Prompt and typing:

net start faxsvc.exe

You can use net stop faxsvc.exe to terminate the service as well.

Another thing is to check for dependencies and restart those as well, i.e. those that the fax service depends on.

EDIT: I guessed this might help, but I didn't read your question very well. I know there's a program called Service Hawk available, but it costs money. Another idea would be to match a batch file that will restart the service every xx seconds/minutes/hours/however long the duration between the service running and failing is.