Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Services Loop Script

Status
Not open for further replies.

PU36

MIS
Mar 16, 2005
202
US
I would like to create a batch file that will loop to checks two services to make sure they are running. If they aren't then start them. The services are 'spooler' and 'ProtectedStorage'.

For some reason they keep stopping and I'm trying to figure out when they are being stopped. I have everything else in the batch set to email me when this occurs, I just can't figure out the "Loop" process.

Thanks
 
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service")
For Each objService in colRunningServices
	If objService.Name = "Spooler" Or objService.DisplayName = "ProtectedStorage" Then
 	    Wscript.Echo objService.DisplayName  & VbTab & objService.State & vbCrLf
 	End IF
Next

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
That will work perfect. I'll just add my own little part that starts the service and sends me an email.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top