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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.