New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Custom VB Script error

Votes:

0

Your Vote:

Up

Down

Dear all,

I use this script in GFI Network Monitor - but it didn't work at PRTG. Many thank's for your help.

Patrick

' /////////////////////////////////////////////////////////////////////////////
'
' ServerServies takes a computer name as an argument and will check that computer
' for all services not in a "Running" state and are set to "Auto" start. There is
' a comma delimited string (strIgnore) that can be used to specify services to 
' ignore if they are not "Running" but set to "Auto" start. A good example is the
' Performance Logs and Alerts service. While the string is comma delimited there 
' is no requirement for the comma except for logical seperation for the programmer.
' /////////////////////////////////////////////////////////////////////////////

Dim ArgObj, i, objWMIService, colItems, strIgnore, stoppedItem
Set ArgObj = WScript.Arguments 
strComputer = ArgObj(0) 
On Error Resume Next
Dim 

' strIgnore is a comma delimited list of "Display Names" of 
' auto start services that are known to not be in a running state.
' Display names can be found via the services snap-in or the "net start"
' command in a cmd.exe window. 
strIgnore = "TSM StorageAgent1,TPM Base Services,Microsoft .NET Framework NGEN v4.0.30319_X64,Microsoft .NET Framework NGEN v4.0.30319_X86,Software Protection,TPM Base Services,Server For NIS,Office Communications Server Monitoring Agent,Internet Connection Sharing (ICS),Security Center,Volume Shadow Copy,Shell Hardware Detection,CONZEPT 16 print processor"+ _
"Performance Logs and Alerts"

' Make a connection via WMI to the argumented remote computer.
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If( Err.Number <> 0 ) Then
ServerServices = retvalUnknown
wscript.echo = "Unable to access '" & strComputer & "'"
wscript.quit("3")
End If

' Make a WMI query for Services (on the remote computer) that are set to 
' auto start but are not in a Running state. (I.E. stopped, pending... etc.)
Set colItems = objWMIService.ExecQuery("select * from Win32_Service " + _
"where State!='Running' and StartMode='Auto'",,48)

' Search the strIgnore string with auto start services that are not running. 
' If a non-running auto start service is not in the strIgnore string, then
' fail and return the service name. Note that if multiple auto start services
' are not running only the first one will be listed. 
For Each stoppedItem in colItems
If instr(strIgnore,stoppedItem.Displayname) = 0 Then 
	wscript.quit("1")
	wscript.echo = "Service Not Started: " & stoppedItem.Displayname
	Exit 
End If
Next

wscript.echo = "All Auto-Start services are in a Running state."&":Ok"
wscript.quit("0")

server-service vbscript wmi

Created on Oct 1, 2012 12:34:53 PM by  Patrick Hauser (0) 1

Last change on Oct 1, 2012 12:40:34 PM by  Konstantin Wolff [Paessler Support]



4 Replies

Votes:

0

Your Vote:

Up

Down

Hi,
first, what is the output when running the script from the commandline?
Second, from a first glance, it seems that the return values are not correct. They have to be in the notation:

value:message

Which means in your case (snippet from your script):

wscript.echo = 2 &":Service Not Started: " & stoppedItem.Displayname

You will have to provide a (random value in your case) which is followed by the message containing all information needed. Furthermore, you might also move the output of the Exit Code

wscript.quit("1")

after the actual return value.
Best regards

Created on Oct 1, 2012 12:45:34 PM by  Konstantin Wolff [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Thank's - but now it works only in a positiv state - if all service started then prtg return a OK Status - if a service is not started then prtg return a error and PE087.

Dim ArgObj, i, objWMIService, colItems, strIgnore, stoppedItem
Set ArgObj = WScript.Arguments 
strComputer = ArgObj(0) 
On Error Resume Next

strIgnore = "TSM StorageAgent1,TPM Base Services,Microsoft .NET Framework NGEN v4.0.30319_X64,Microsoft .NET Framework NGEN v4.0.30319_X86,Software Protection,TPM Base Services,Server For NIS,Office Communications Server Monitoring Agent,Internet Connection Sharing (ICS),Security Center,Volume Shadow Copy,Shell Hardware Detection,CONZEPT 16 print processor,Performance Logs and Alerts"

Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")

If( Err.Number <> 0 ) Then
 ServerServices = retvalUnknown
 wscript.echo = 3 & ":Unable to access '" & strComputer & "'"
 wscript.quit("3")
End If

Set colItems = objWMIService.ExecQuery("select * from Win32_Service " + "where State != 'Running' and StartMode ='Auto'",,48)

For Each stoppedItem in colItems
 If instr(strIgnore,stoppedItem.Displayname) = 0 Then 
	wscript.echo = 2 & ":Service Not Started: " & stoppedItem.Displayname
	wscript.quit("2")
 End If
Next

wscript.echo "All Auto-Start services are in a Running state."&":OK"
wscript.quit("0")

Created on Oct 1, 2012 1:55:28 PM by  Patrick Hauser (0) 1



Votes:

0

Your Vote:

Up

Down

Hi,
the code PE087 means that there is no response from the script at all (Check this article for a detailed overview of the PE error codes). You might want to check your if conditions whether the script gets stuck somewhere.
Furthermore, you might additional want to adjust the final return value as well:

wscript.echo "All Auto-Start services are in a Running state."&":OK"
wscript.quit("0")

to something like this:

wscript.echo 1 & ":All Auto-Start services are in a Running state."&":OK"
wscript.quit("0")

Best regards

Created on Oct 1, 2012 2:07:04 PM by  Konstantin Wolff [Paessler Support]



Votes:

0

Your Vote:

Up

Down

OK - now it works with an object trigger:

Dim ArgObj, i, objWMIService, colItems, strIgnore, stoppedItem, dada
Set ArgObj = WScript.Arguments 
strComputer = ArgObj(0) 
On Error Resume Next

strIgnore = "TSM StorageAgent1,TPM Base Services,Microsoft .NET Framework NGEN v4.0.30319_X64,Microsoft .NET Framework NGEN v4.0.30319_X86,Software Protection,TPM Base Services,Server For NIS,Office Communications Server Monitoring Agent,Internet Connection Sharing (ICS),Security Center,Volume Shadow Copy,Shell Hardware Detection,CONZEPT 16 print processor,Performance Logs and Alerts"

Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")

If( Err.Number <> 0 ) Then
 ServerServices = retvalUnknown
 wscript.echo ":Unable to access " & strComputer
 wscript.quit("2")
End If

Set colItems = objWMIService.ExecQuery("select * from Win32_Service " + "where State != 'Running' and StartMode ='Auto'",,48)

For Each stoppedItem in colItems
 If instr(strIgnore,stoppedItem.Displayname) = 0 Then 
	wscript.echo ":Service Not Started = " & stoppedItem.Displayname 
	wscript.quit("1")
 End If
Next

wscript.echo ":All Auto-Start services are in a Running state."
wscript.quit("0")

Created on Oct 3, 2012 12:17:36 PM by  Patrick Hauser (0) 1

Last change on Feb 21, 2018 1:40:38 PM by  Luciano Lingnau [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.