Это немного некрасиво, но вы, вероятно, можете изменить его в соответствии со своими потребностями. Просто установите запланированное задание, чтобы вызывать скрипт так часто.
Dim ServiceDown
Dim Message
Function sGetServiceStatus(ByVal strServiceName)
wbemImpersonationLevelImpersonate = 3
wbemAuthenticationLevelPktPrivacy = 6
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer("localhost")
objWMIService.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate
objWMIService.Security_.AuthenticationLevel = wbemAuthenticationLevelPktPrivacy
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where DisplayName ='"& strServiceName & "'")
if(colListOfServices.Count=0) then
sGetServiceStatus = ""
Exit function
end if
For Each objItem in colListOfServices
If objItem.DisplayName = strServiceName and objItem.State = "Running" Then
sGetServiceStatus = objItem.State
Exit Function
else
sGetServiceStatus = objItem.State
ServiceDown = True
Message = Message & vbcrlf & strServiceName
Exit function
End If
Next
sGetServiceStatus = ""
End Function
sGetServiceStatus("ISC BIND")
sGetServiceStatus("Apache2.2")
sGetServiceStatus("MySQL")
If ServiceDown Then
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Check Services"
objMessage.From = "admin@yourhost.com"
objMessage.To = "admin@yourhost.com"
objMessage.TextBody = "The following service(s) is/are down: " & Message
objMessage.Send
End If