How to monitor whether an application is running on Windows Server 2008

monitoringprocesswindows-server-2008

We're mostly a Linux shop, but we have a print server running Windows Server 2008, and use an application called Print Helper to print invoices. I need to find a way to check that this application is running, and automatically restart it if it's not.

On Linux I'd probably do this with a small shell script and a cron job, but I'm not sure how to accomplish this on Windows Server. I'm fairly confident I could do it in Perl using Proc::Background, but I'm reluctant to install Perl just for one script, and while I'm sure it can be done using something like PowerShell, it's not really a worthwhile use of my time to learn PowerShell for one small task. Tasklist seems to do some of what I want in that it can let you know if a specific process is running or not, but I'm not sure how I could go from there to automatically restarting the application if it's crashed.

Any help gratefully received!

Best Answer

Wow. I just answered a different question.

What you should do is "daemonize" the Print Helper process by using sc.exe or srvany.exe (which I believe is depreciated). Then you can utilize the builtin service "Recovery" options to handle failure events (including, I believe, executing a script, sending an snmp trap, sending an email, and, of course, restarting the service).

As given:

sc create printhelper binpath= "c:\program files\Print Helper\phelper.exe" start= auto depend= Spooler/lanmanserver DisplayName= "Print Helper"

This will create a service named printerhelper, with a display name of Print Helper, executing "c:\program files\Print Helper\phelper.exe" automatically, with the dependencies of the Print Spooler and SMB/CIFS Server service, running as NT AUTHORITY\SYSTEM builtin user.