You’ve probably heard me mention that I don’t like for my users to be my “system unavailable” alerts. I want to know as soon as, if not before, they do. The challenge is how to monitor these service states (Discoverer, Hyperion, Informatica, and Glassfish) on Windows boxes in the absence of some tool I have to purchase. I did a bit of research and have, from a number of other sites, combined some solutions to developed a quick and dirty way to check the status of Windows services right here from my desktop. If you haven’t already, check out the ‘sc’ command. There’s a lot of stuff you can do. I am going to focus on the ‘query’ option and creating a .bat file to check your services.
Here is my code: (Feel free to copy)
FOR /F “tokens=1-2 delims= ” %%x in filename
for /F “tokens=3 delims=: ” %%D in (‘sc %%x query %%y ^| findstr ” STATE”‘) do (^
if %%D NEQ RUNNING (
msg dbryant %%y %%D on %%x reported at %time%
echo %%y %%D on %%x reported at %time%
echo %%y %%D on %%x reported at %time% >> svclog.txt
echo Next poll in 5 seconds
ping -n 5 127.0.0.1>nul
Let’s break this down a bit:
Create a file with the following construct ‘\servername servicename and list your servers and services one per line.
and save it as filename
Create a .bat file and for ease of use, save in the same directory as the .txt file.
The important part in the BAT file (example above) is:
if %%H NEQ RUNNING (
The preceding line is for looping through the text file.
Using the first line of the text file, this line, in essence executes the following:
sc \DISCOVER-02 query Glassfish
and looks for the service STATE to return its status.