View Single Post
Old 04-17-2009, 05:22 PM   #9
CrackBerry Addict
Join Date: Jan 2008
Model: 9700
Carrier: Rogers
Posts: 709

I had similar problems that eventually went away but I wrote a batch script to restart said services that I still run every 5 minutes. It's fairly generic as you can see. You create a list of services by simply running "net start >MasterServicesList.txt" and move that file into the directory where the batch program is. You can cut the list of services down to just what you want to monitor as well. It requires:

- blat to send the email alert out - also residing in the directory of the bstch file.
- A directory called ServicesNotStarted in the directory
- command extensions enabled
- A command argument of /ServiceRestart=YES if you want it to restart the services

Some tweaking is in order for the variables to suit your needs.

rem ***************** Service Error Handler **********************
rem * Version 1.00                                               *
rem **************************************************************
rem Reset and initialize variables

set servicefailcount=
set servicename=
set ServiceRestart=
set StartPath=%~dp0
set EmailText=%StartPath%Email.txt
set EmailServer=exchange:25
set EmailSubject=Service Failure on %ComputerName%
set MasterServicesList=%StartPath%MasterServicesList.txt
set CurrentServicesList=%StartPath%CurrentServicesList.txt
set ServicesNotStarted=%StartPath%ServicesNotStarted.txt
set ServicesReStarted=%StartPath%ServicesReStarted.txt

del %ServicesNotStarted%
del %EmailText%


if "%1"=="" goto StartProcessing


echo %1 | find "/"
if errorlevel 1 goto ParameterFailure


if /i "%1"=="/ServiceRestart" set ServiceRestart=%~2& goto FoundParameter


goto ParameterFailure


goto enumerateparameters


echo Parameter Failure! > %EmailText%
echo. >> %EmailText%
echo These were the command line parameters given: %* >> %EmailText%
goto email


if exist %MasterServicesList% goto CompareCurrentToMaster
echo Master Services List has not been created! > %EmailText%
echo. >> %EmailText%
echo Some services MAY NOT BE RUNNING >> %EmailText%
goto email


net start > %CurrentServicesList%
for /f "skip=2 delims=," %%i in (%MasterServicesList%) do (
	set CurrentService=%%i
	set CurrentService=!CurrentService:~3!
	find "!CurrentService!" %CurrentServicesList%
	if errorlevel 1 (
		if not exist "%StartPath%ServicesNotStarted\!CurrentService!" (
			echo !CurrentService!>> %ServicesNotStarted%
			echo. > "%StartPath%ServicesNotStarted\!CurrentService!"
	) else (
		if exist "%StartPath%ServicesNotStarted\!CurrentService!" echo !CurrentService!>> %ServicesReStarted%
		del "%StartPath%ServicesNotStarted\!CurrentService!"

if not exist %ServicesNotStarted% if not exist %ServicesRestarted% goto cleanup

echo Service Restart?: %ServiceRestart% >> %EmailText%
echo. >> %EmailText%

if not exist %ServicesReStarted% goto ServicesNotStarted


echo Services that have ReStarted:>> %EmailText%
echo. >> %EmailText%
type %ServicesReStarted% >> %EmailText%
echo. >> %EmailText%

if not exist %ServicesNotStarted% goto footer


echo Services Currently Not Running:>> %EmailText%
echo. >> %EmailText%
for %%i in (%StartPath%ServicesNotStarted\*.*) do echo %%~ni Since: %%~ti>> %EmailText%
echo. >> %EmailText%
if /i NOT "%ServiceRestart%"=="YES" goto footer
echo Services Restarting - Results Below: >> %EmailText%
echo. >> %EmailText%
for %%i in (%StartPath%ServicesNotStarted\*.*) do (
	net stop "%%~ni" >> %EmailText%
	net start "%%~ni" >> %EmailText%


echo Current Running Services: >> %EmailText%
echo. >> %EmailText%
net start  >> %EmailText%


%StartPath%blat %EmailText% -q -to %EmailTo% -s "%EmailSubject%" -f %EmailFrom% -server %EmailServer% -priority 1


del %emailtext%
del %ServicesNotStarted%
del %ServicesReStarted%
del %CurrentServicesList%
set servicefailcount=
set servicename=
set ServiceRestart=
set StartPath=
set EmailText=
set EmailServer=
set EmailFrom=
set EmailTo=
set EmailSubject=

Offline   Reply With Quote