What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

How can I check which codes are returned when monitoring Windows services via WMI?

Votes:

0

I use WMI Service sensors to monitor some standard Windows services. I set the sensor to restart the service if it is not running anymore, but PRTG does not restart the service. Is there a possibility for debugging?

custom-exe custom-script-exe custom-sensor debug prtg vbscript windows wmi wmi-service

Created on Feb 12, 2013 10:13:10 AM by  Gerald Schoch [Paessler Support]

Last change on Mar 19, 2015 3:39:38 PM by  Martina Wittmann [Paessler Support]



1 Reply

Accepted Answer

Votes:

0

This article applies to PRTG Network Monitor 12 or later

Debugging WMI Service Sensors

You can test the return codes of the respective WMI Services while starting with the custom script below. Copy this Visual Basic Script (VBScript) into a text editor and save it as *.vbs file. Then copy this file to the \Custom Sensors\EXE sub folder of the PRTG program directory.

Create a EXE/Script Sensor in PRTG and select this script.

The results can help our technical support team to investigate the issue. Please open a support ticket and send us the results you get.


' *********************************************************************
' PRTG Custom EXE Sensor, VB Demo Script for starting a service via WMI
' *********************************************************************
' created Feb 2013 for PRTG Network Monitor by Paessler Support Team, www.paessler.com
' This script is Open Source and comes without support and warranty
' *********************************************************************
' Provide two Parameters: computer name running the service and service name.
' Include Parameters containing spaces in quotation marks (e.g. "My Service Name")
' *********************************************************************
' You can find explanations for the result codes here:
' http://msdn.microsoft.com/en-us/library/windows/desktop/aa393660%28v=vs.85%29.aspx
 
if WScript.Arguments.Count <> 4 then
 WScript.echo "Wrong number of  Arguments." & _
              " Please provide Computername,Domain\User,Password and Servicename." & _
              " Include Parameters containing spaces in quotation marks (e.g. ""My Service Name""). "& _
              " Leave User and Password blank (i.e. """" """") for local computer"
 wscript.quit("2")
else

  strNamespace = "root/cimv2"

  strComputer = WScript.Arguments(0)
  strUser = WScript.Arguments(1)
  strPassword = WScript.Arguments(2)
  strService = WScript.Arguments(3)

  Set objLocator = CreateObject("WbemScripting.SWbemLocator")
  Set objWMIService = objLocator.ConnectServer(strComputer,strNamespace,strUser,strPassword)

  Set colServices = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='" & strService & "'")
 
    For Each objService in colServices
    Return = objService.StartService()
    If Return <> 0 Then
        Wscript.Echo "StartService method returned error code = " & Return
        wscript.quit("2")
    Else
      WScript.Echo "OK:0"
      wscript.quit("0")
    End If
  Next
end if

Created on Feb 12, 2013 10:19:51 AM by  Gerald Schoch [Paessler Support]

Last change on Feb 12, 2013 1:12:17 PM by  Daniel Zobel [Product Manager]




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.