| | | Forum Newbie
       
Group: Forum Members Last Login: 11/20/2008 3:23:22 PM Posts: 3, Visits: 28 |
| | I am running WUG v12 and I am looking for a way to monitor a NT service using VBScript if possible. I currently use an Active Script to monitor whether a process is running or not and this has been working fine. I tried using the NT Service Monitor to monitor if a service has started or not but I get the RPC Server is not available a few times through out the day which give a false indication that the service is down. Any assitance would be appreciated. |
| | | | Forum Guru
       
Group: Forum Members Last Login: 6/26/2009 8:28:52 AM Posts: 65, Visits: 601 |
| Try this:
------------------------------------------------------------------------------------
Option Explicit
Dim sAddress, objWMIService, colService, objService, strComputer
sAddress = Context.GetProperty("Address")
'Sending log message to the WhatsUp Event Viewer; change to the name of the service you are monitoring
Context.LogMessage "Checking for on " & sAddress
strComputer = sAddress
'Set the default result code of the check (0=Success, 1=Error)
Context.SetResult 1, "Service is not running"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select DisplayName, Status from Win32_Process")
' DisplayName is the name of the service as it appears in the Services applet; you can also use Name, which is the actual name of the service
For Each objService in colService
If objService.Name = "" AND objService.Status = "Running" Then Context.SetResult 0, "No error"
' Change to the exact name of the service you want to monitor; make sure the case matches
Next
Set colService = Nothing
Set objWMIService = Nothing |
| | | | Forum Newbie
       
Group: Forum Members Last Login: 11/20/2008 3:23:22 PM Posts: 3, Visits: 28 |
| | Thank you reply. I am pretty new at Active Scripting and I am assuming I need to enter the name of the service I want to monitor somewhere in the script. Is it possible you can direct me? Thanks |
| | | | Forum Newbie
       
Group: Forum Members Last Login: 4/29/2009 11:39:12 AM Posts: 6, Visits: 93 |
| You'll have to add a "where" clause to the select statement...
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select DisplayName, Status from Win32_Process where DisplayName = 'THE NAME OF THE SERVICE'")
' DisplayName is the name of the service as it appears in the Services applet; you can also use Name, which is the actual name of the service |
| | | | Forum Guru
       
Group: Forum Members Last Login: 6/26/2009 8:28:52 AM Posts: 65, Visits: 601 |
| csosa (10/30/2008) Thank you reply.
I am pretty new at Active Scripting and I am assuming I need to enter the name of the service I want to monitor somewhere in the script. Is it possible you can direct me?
Thanks
Sometimes, what you type and what shows up are 2 different things. The line should have read:
For Each objService in colService
If objService.Name = "servicename" AND objService.Status = "Running" Then Context.SetResult 0, "No error"
' Change "servicename" to the exact name of the service you want to monitor; make sure the case matches
Next
Or, you could use the Where clause as someone else suggested:
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select DisplayName, Status from Win32_Process where DisplayName = 'servicename' and status = 'Running'")
' DisplayName is the name of the service as it appears in the Services applet; you can also use Name, which is the actual name of the service
and take out this section:
For Each objService in colService
If objService.Name = "" AND objService.Status = "Running" Then Context.SetResult 0, "No error"
' Change to the exact name of the service you want to monitor; make sure the case matches
Next |
| | | | Forum Newbie
       
Group: Forum Members Last Login: 1/12/2009 7:36:31 PM Posts: 5, Visits: 41 |
| | Hello, how I can restart a service using Active Script? Many thanks! |
| |
|
|