Active Script for monitoring NT Service

To the Ipswitch web site

Ipswitch Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Active Script for monitoring NT ServiceExpand / Collapse
Author
Message
Posted 10/29/2008 11:16:16 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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.

Post #48240
Posted 10/30/2008 8:44:54 AM
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum 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
Post #48273
Posted 10/30/2008 9:56:41 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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

Post #48278
Posted 10/30/2008 11:33:50 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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
Post #48282
Posted 10/30/2008 2:51:08 PM
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum 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
Post #48288
Posted 12/4/2008 3:34:24 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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!

Post #49202
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Dave, Mark Singh, kevin r gillis, Jason Benton, Christian Lawson, Brandon Felger, Tripp Allen, Will Sansbury, Jason Williams, Hush, FTPplanet.com, Hugh Garber, WUP-PM, mmulryan@ipswitch.com, mswimm

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 6:23pm

Powered By InstantForum.NET v4.1.4 © 2009
Execution: 0.047. 10 queries. Compression Enabled.