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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to check on service status

Status
Not open for further replies.

rr27

MIS
Nov 18, 2005
69
US
I'm new to VBS so please bare with me. I have a win2k3 server that I would like to monitor 2 critical services on. I would like to write a vbscript that polls the service every hour and if the service is not running will send an email out. How do I go about doing this?
 
Ok...one more question. Again I'm new to VBscripting: How would I add email notification to this script when the spoolsv.exe service stops. I have an exchange server if this matters or not.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService. _
ExecNotificationQuery("Select * from __instancemodificationevent " _
& "within 30 where TargetInstance isa 'Win32_Service'")
i = 0
Do While i = 0
Set objService = colServices.NextEvent
If objService.TargetInstance.State <> _
objService.PreviousInstance.State Then
Wscript.Echo objService.TargetInstance.Name _
& " is " & objService.TargetInstance.State _
& ". The service previously was " & _
objService.PreviousInstance.State & "."
End If
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top