To create this service, copy the following code to a cmd file and setup a schedule task. (Replace YourServiceName with the actual name of your service)
@ECHO OFF
set logFile=c:\temp\svcmonitor.log
set tempFile=c:\temp\tmp.txt
set serviceName=YourServiceName
sc query %serviceName% > %tempFile%
for /F "skip=3 tokens=1,4" %%i in (%tempFile%) do if %%i equ STATE (
if %%j equ STOPPED (
echo %date% %time% %serviceName% service is stopped. Trying to restart. >> %logFile%
sc start %serviceName% >> %logFile%
echo %date% %time% %serviceName% restarted >> %logFile%
) else (
echo %date% %time% %serviceName% service is %%j >> %logFile%
)
)
Now update the scheduled task in to run every day. Then go to the advanced scheduling options menu and set to repeat the task every 10 minutes(or what ever frequency deemed appropriate for your task) as shown below. Now you have a poor man's version of a windows service monitor.
No comments:
Post a Comment