A colleague of mine was having issue with his “Microsoft Exchange Information Store” service it got stopped at certain time after some schedule job of defragmentation and it actually cause the Mail store to un-mount. So he had to get up early in the morning to just restart the service.

I suggested him that before he find more permanent solution to the problem I could write him a small batch script to start the service if it is stopped and then he could configure it as scheduled task to run after certain period of time to check if service is not running then it will start it. Ideally we should use PowerShell script instead of a batch script power shell is really a powerful shell. I used batch since he was using windows 2003 server so it’s easier to run batch then PowerShell.

To cut the long story short below is a simple script which checks if service is running or not using a “net start” piped with “find” command. Name given as parameter to find is “Display Name” of service and if that name is not found which means service is not running which causes errorlevel=1 which is checked through “IF” expression and when it’s true inside of “IF” is executed. In IF “Net Start” command is used to start the service with “Service Name”, below figure 1 shows where to look for these names.

Also you might have noticed “>>” redirection operator. This is used to redirect output of console to a file so that we could log the result in a text file to keep track of what happened when.

Just save the below content in a “.bat” and schedule it as job with windows scheduler with as many “Reoccurrence” as you want since it will start the service if it’s stopped otherwise it will do nothing and there you have it a quick and dirty windows service watcher.

echo on

net start | find /i “Microsoft Exchange Information Store”

If errorlevel== 1 (

net start “MSExchangeIS” >> c:\ServiceCheck.log

Date /T >> c:\ServiceCheck.log

Time /T >> c:\ServiceCheck.log


Figure 1 to find out “Display Name” and “Service Name”