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")
Article Comments
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")
Oct, 2012 - Permalink
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
Oct, 2012 - Permalink
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")
Oct, 2012 - Permalink
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:
Which means in your case (snippet from your script):
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
after the actual return value.
Best regards
Oct, 2012 - Permalink