Script Engine Package Run Time Report Probe

Microsoft.Amalga.UIS.2009.Monitoring.ScriptEnginePackageRuntimeReportProbe (ProbeActionModuleType)

This probe is intended to be called from an administrative task and for the purpose of on-demand time checks on packages. It checks per server, per service, or per package, depending on the parameters passed in. The probe checks a script engine package's last processed timestamp and compares it against the current time, then determines if the time delta is within tolerance, or if the delta is above warning or critical time thresholds.

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
PackageRunTimeReportProbe ProbeAction Microsoft.Windows.ScriptProbeAction Default
PassThrough ProbeAction System.PassThroughProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds
DebugEnabledbool$Config/DebugEnabled$Log EnabledFor debugging management pack script issues. Not recommended for general use.
WarningMinutesint$Config/WarningMinutes$Warning Minutes
CriticalMinutesint$Config/CriticalMinutes$Critical Minutes

Source Code:

<ProbeActionModuleType ID="Microsoft.Amalga.UIS.2009.Monitoring.ScriptEnginePackageRuntimeReportProbe" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" name="DebugEnabled" type="xsd:boolean"/>
<xsd:element minOccurs="1" name="WarningMinutes" type="xsd:integer"/>
<xsd:element minOccurs="1" name="CriticalMinutes" type="xsd:integer"/>
<xsd:element minOccurs="1" name="ServiceInstanceName" type="xsd:string"/>
<xsd:element minOccurs="1" name="PackageName" type="xsd:string"/>
<xsd:element minOccurs="1" name="DebugEventSource" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="DebugEnabled" Selector="$Config/DebugEnabled$" ParameterType="bool"/>
<OverrideableParameter ID="WarningMinutes" Selector="$Config/WarningMinutes$" ParameterType="int"/>
<OverrideableParameter ID="CriticalMinutes" Selector="$Config/CriticalMinutes$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PackageRunTimeReportProbe" TypeID="Windows!Microsoft.Windows.ScriptProbeAction">
<ScriptName>Amalga2009PackagesRunTimeReport.vbs</ScriptName>
<Arguments>"$Target/Id$"</Arguments>
<ScriptBody><Script>'''
'' Amalga2009PackagesRunTimeReport.vbs
''

''------------------------------------------------------------------------------------------
Option Explicit
SetLocale("en-us")

const SCRIPT_VERSION = "1.0"
dim WRITELINEHEADER
WRITELINEHEADER = "Amalga2009PackagesRunTimeReport.vbs" &amp; vbcrlf &amp; "Microsoft.Amalga.UIS.2009.Monitoring.ScriptEnginePackageRuntimeReportProbe" &amp; vbcrlf &amp; "script version: " &amp; SCRIPT_VERSION &amp; vbcrlf &amp; "script start: " &amp; now()


const EXPECTED_PARAM_COUNT = 1

const LOGSEVERITY_INFO = 4
const LOGSEVERITY_WARN = 2
const LOGSEVERITY_ERROR = 1

dim LogEnabled
LogEnabled = false
dim ManagedEntityId
ManagedEntityId = ""

Dim oAPI
Set oAPI = CreateObject("MOM.ScriptAPI")


dim DebugEventSource
dim LogEventSource
dim LogSeverity
LogSeverity = LOGSEVERITY_INFO

DebugEventSource = "$Config/DebugEventSource$"
if instr(DebugEventSource,"$") then
LogEventSource = "Amalga"
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in DebugEventSource - $ not translated - " &amp; DebugEventSource
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
else
LogEventSource = trim(DebugEventSource &amp; "")
if (LogEventSource = "") then
LogEventSource = "Amalga"
LogEnabled = true
LogSeverity = LOGSEVERITY_WARN
WriteLine "missing DebugEventSource, defaulting to 'Amalga'"
LogEnabled = false
LogSeverity = LOGSEVERITY_INFO
end if
end if

Dim oArgs
Set oArgs = WScript.Arguments

DumpArgs(oArgs)

if (oArgs.Count &lt;&gt; EXPECTED_PARAM_COUNT) then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "invalid arg count: " &amp; oArgs.Count &amp; " expected " &amp; EXPECTED_PARAM_COUNT
oArgs = cdate("invalid arg count") ''' intentionally crash
end if


ManagedEntityId = GetArg(oArgs(0))


dim DebugEnabled
DebugEnabled = "$Config/DebugEnabled$"
if instr(DebugEnabled,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in DebugEnabled - $ not translated - " &amp; DebugEnabled
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
DebugEnabled = trim(ucase(DebugEnabled &amp; " "))
LogEnabled = (DebugEnabled = "TRUE")


Dim gserviceinstancename, gpackagename, warningMinutes, criticalMinutes

gserviceinstancename = "$Config/ServiceInstanceName$"
if instr(gserviceinstancename,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in gserviceinstancename - $ not translated - " &amp; gserviceinstancename
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if

gpackagename = "$Config/PackageName$"
if instr(gpackagename,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in gpackagename - $ not translated - " &amp; gpackagename
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if

warningMinutes = "$Config/WarningMinutes$"
if instr(warningMinutes,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in warningMinutes - $ not translated - " &amp; warningMinutes
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if

criticalMinutes = "$Config/CriticalMinutes$"
if instr(criticalMinutes,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in criticalMinutes - $ not translated - " &amp; criticalMinutes
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if


''------------------------------------------------------------------------------------------


Dim retval


WriteLine("LogEnabled=" &amp; LogEnabled &amp; "(DebugEnabled=" &amp; DebugEnabled &amp; ")")
WriteLine("serviceinstancename=" &amp; gserviceinstancename)
WriteLine("packagename=" &amp; gpackagename)
WriteLine("warningMinutes=" &amp; warningMinutes)
WriteLine("criticalMinutes=" &amp; criticalMinutes)


WriteLine("checking the registry for package's state keys")

dim oReg, strComputer, strKeyPath, arrValueNames, keyfound, LastUpdated, LastProcessed, strValueName, strValue, valuefound
dim ActiveTimeBias, deltayears, deltamonths, deltadays, deltahours, deltaminutes, deltaseconds, status, pos
dim Date1LessThanDate2, totalMinutesBehind

Const HKEY_LOCAL_MACHINE = &amp;H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; _
strComputer &amp; "\root\default:StdRegProv")


strKeyPath = "SOFTWARE\Microsoft\Amalga\2.0\ScriptEngine\"

If oReg.EnumKey (HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames) = 0 Then
WriteLine("The registry path exists " &amp; strKeyPath)
keyfound = true
Else
WriteLine("The registry path does not exist " &amp; strKeyPath)
keyfound = false
end if

if (keyfound) then
if (ucase(trim(gserviceinstancename)) = "ALL") then
wscript.echo "Enumerating all services, all packages"
call EnumerateServices()
else
if (ucase(trim(gpackagename)) = "ALL") then
wscript.echo "Enumerating all packages for service: " &amp; gserviceinstancename
wscript.echo "----------"
call EnumeratePackages(gserviceinstancename)
else
wscript.echo "Getting report for service: " &amp; gserviceinstancename &amp; " package: " &amp; gpackagename
wscript.echo "----------"
call ReportServiceTime(gserviceinstancename, gpackagename)
end if
end if
else
wscript.echo "ERROR: package state keys root not found"
end if


WriteLine("end script.")


'////////////////////////////
sub EnumerateServices()

dim oReg, strComputer, strKeyPath, arrSubKeys, i, serviceinstancename

wscript.echo "----------"

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; _
strComputer &amp; "\root\default:StdRegProv")


strKeyPath = "SOFTWARE\Microsoft\Amalga\2.0\ScriptEngine\DiscoveryData\ServiceInstances"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

dim numSubKeys
numSubKeys = -1

on error resume next
numSubKeys = UBound(arrSubKeys)
on error goto 0

if (numSubKeys &gt;= 0) then
For i = 0 to numSubKeys
WriteLine("processing service " &amp; i &amp; "...")
serviceinstancename = arrSubKeys(i)
WriteLine("Service instance name: " &amp; serviceinstancename)
call EnumeratePackages(serviceinstancename)
Next
else
WriteLine("The sub key count for services is &lt; 1 (" &amp; numSubKeys &amp; ")")
end if

end sub
'////////////////////////////
sub EnumeratePackages(serviceinstancename)

dim oReg, strComputer, strKeyPath, arrSubKeys, i, packagename


strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; _
strComputer &amp; "\root\default:StdRegProv")


strKeyPath = "SOFTWARE\Microsoft\Amalga\2.0\ScriptEngine\DiscoveryData\ServiceInstances\" &amp; serviceinstancename
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

dim numSubKeys
numSubKeys = -1

on error resume next
numSubKeys = UBound(arrSubKeys)
on error goto 0

if (numSubKeys &gt;= 0) then
For i = 0 to numSubKeys
WriteLine("processing packagename " &amp; i &amp; "...")
packagename = arrSubKeys(i)
WriteLine("packagename name: " &amp; packagename )
call ReportServiceTime(serviceinstancename, packagename)
Next
else
WriteLine("The sub key count for packages is &lt; 1 (" &amp; numSubKeys &amp; ")")
end if


end sub
'////////////////////////////
sub ReportServiceTime(serviceinstancename, packagename)

dim strKeyPath
strKeyPath = "SOFTWARE\Microsoft\Amalga\SCOM\Volatile\2.0\ScriptEngine\" &amp; serviceinstancename &amp; "\" &amp; packagename ''' not trailing backslash here
dim RegValuePrefixName
RegValuePrefixName = "MessagesReceived"

dim OldRetVal_MessagesReceived
OldRetVal_MessagesReceived = ucase(GetOldRetVal(strKeyPath, RegValuePrefixName))

dim serviceRunning, packageRunning
serviceRunning = IsServiceRunning(serviceinstancename)
packageRunning = false
if (not serviceRunning) then
retval = "SERVICE_STOPPED"
status = ""
elseif (OldRetVal_MessagesReceived = "NO_CHANGE") then
retval = "NO_CHANGE"
status = "'Message Received' counter has not moved since last check, assuming caught up."
else
packageRunning = IsPackageRunning(packagename)
if (not packageRunning) then
retval = "PACKAGE_STOPPED"
status = ""
elseif (OldRetVal_MessagesReceived = "") then
retval = "MISSING_REG"
status = ""
end if
end if

if (packageRunning) then

dim oReg, strComputer, arrSubKeys, i, keyfound, arrValueNames, strValueName, strValue


strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; _
strComputer &amp; "\root\default:StdRegProv")



strKeyPath = "SOFTWARE\Microsoft\Amalga\2.0\ScriptEngine\" &amp; serviceinstancename &amp; "\" &amp; packagename &amp; "\"

If oReg.EnumKey (HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames) = 0 Then
WriteLine("The registry path exists " &amp; strKeyPath)
keyfound = true
Else
WriteLine("The registry path does not exist " &amp; strKeyPath)
keyfound = false
end if


If (keyfound) Then

WriteLine("found package's state keys, starting building discovery objects")

strValueName = "Status.Processed.Last"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
LastProcessed = strValue &amp; ""
WriteLine("LastProcessed: " &amp; LastProcessed)
if LastProcessed = "" then
LastProcessed = 0
valuefound = false
else
valuefound = true
end if
pos = instr(LastProcessed,".")
if (pos&gt;0) then LastProcessed = left(LastProcessed,pos-1)
WriteLine("LastProcessed: " &amp; LastProcessed)

LastUpdated = now()
WriteLine("LastUpdated: " &amp; LastUpdated)

strValueName = "ActiveTimeBias"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,"System\CurrentControlSet\Control\TimeZoneInformation\",strValueName,strValue
ActiveTimeBias = strValue &amp; ""
WriteLine("ActiveTimeBias: " &amp; ActiveTimeBias)
if (ActiveTimeBias = "") then ActiveTimeBias = 0
WriteLine("ActiveTimeBias: " &amp; ActiveTimeBias)


LastProcessed = DateAdd("n",(-1*ActiveTimeBias),LastProcessed)
WriteLine("LastProcessed: " &amp; LastProcessed)

Date1LessThanDate2 = GetDateDiff(LastProcessed, LastUpdated, deltayears, deltamonths, deltadays, deltahours, deltaminutes, deltaseconds)

totalMinutesBehind = (deltayears * 365 * 24 * 60) + (deltamonths * 30 * 24 * 60) + (deltadays * 24 * 60) + (deltahours * 60) + (deltaminutes)

WriteLine ("totalMinutesBehind: " &amp; totalMinutesBehind)

if (not valuefound) then
status = "The package has not process any messages. Status.Processed.Last value not found - " &amp; strKeyPath
retval = "UNEXPECTED"
else
if (retval = "MISSING_REG") then
status = "Ensure the dependent monitor 'Package is receiving messages' is enabled."
elseif (not Date1LessThanDate2) then
status = "Last Processed (time zone adjusted) &gt; Last Checked Time"
retval = "UNEXPECTED"
else
if (clng(totalMinutesBehind) &gt; clng(criticalMinutes)) then
status = "delta is &gt; " &amp; criticalMinutes &amp; " min (CRITICAL)"
retval = "CRITICAL"
else
if (clng(totalMinutesBehind) &gt; clng(warningMinutes)) then
status = "delta is within " &amp; warningMinutes &amp; "-" &amp; criticalMinutes &amp; " min (WARNING)"
retval = "WARNING"
else
status = "delta is &lt; " &amp; warningMinutes &amp; " min (HEALTHY)"
retval = "HEALTHY"
end if
end if
end if
end if

wscript.echo ucase(retval)
wscript.echo "Package:" &amp; packagename
wscript.echo "Service:" &amp; serviceinstancename
wscript.echo status
if (valuefound) then
wscript.echo "Last Checked Time:" &amp; LastUpdated
wscript.echo "Last Processed:" &amp; LastProcessed
wscript.echo "Warning Minutes Range:" &amp; warningMinutes
wscript.echo "Critical Minutes Range:" &amp; criticalMinutes
wscript.echo "Total Minutes Behind: " &amp; totalMinutesBehind
wscript.echo "Delta Times: " &amp; deltaYears &amp; "y " &amp; deltaMonths &amp; "m " &amp; deltaDays &amp; "d " &amp; deltaHours &amp; "h " &amp; deltaMinutes &amp; "n " &amp; deltaSeconds &amp; "s"
end if

else
retval = "UNEXPECTED"
status = "timestamp keys not found - " &amp; strKeyPath

wscript.echo ucase(retval)
wscript.echo status
wscript.echo "Package:" &amp; packagename
wscript.echo "Service: " &amp; serviceinstancename

end if

else '' package not running
wscript.echo ucase(retval)
if status &lt;&gt; "" then
wscript.echo status
end if
wscript.echo "Package:" &amp; packagename
wscript.echo "Service: " &amp; serviceinstancename
end if

wscript.echo "----------"

end sub
'////////////////////////////

''------------------------------------------------------------------------------------------

'////////////////////////////

sub DumpArgs(Args)
dim i, status
WriteLine("Dumping args as passed in.")
WriteLine("Note: If you see quotes, they are actually part of the argument literal.")
dim untranslated
untranslated = false
status = "Args: "
for i = 0 to Args.Count - 1
status = status &amp; Args(i) &amp; " "
WriteLine(i &amp; ": " &amp; Args(i))
if (instr(Args(i),"$") &gt; 0) then
untranslated = true
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine("ERROR: untranslated $ encountered at arg " &amp; i &amp; ": " &amp; Args(i))
end if
next
if (untranslated) then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine("ERROR: one or more untranslated $ args encountered, quitting.")
status = cdate("ERROR: one or more untranslated $ args encountered, quitting.") ''' intentionally crash here
end if

end sub

'////////////////////////////

function GetArg(quotedarg)
dim s
s = quotedarg
if s &lt;&gt; "" then
if mid(s,1,1) = """" then
s = mid(s,2, len(s)-1)
end if
if mid(s,len(s),1) = """" then
s = mid(s, 1, len(s)-1)
end if
end if
GetArg = s
end function

'////////////////////////////

sub WriteLine(in_line)

dim s

s = vbcrlf &amp; "ID: " &amp; ManagedEntityId &amp; vbcrlf &amp; WRITELINEHEADER &amp; vbcrlf &amp; vbcrlf &amp; in_line

if (LogEnabled) then
wscript.echo in_line
call oAPI.LogScriptEvent(LogEventSource, 100, LogSeverity, s)
end if

end sub

'////////////////////////////

function GetDomainFromTargetComputer(machinename)
dim pos, temp
temp = machinename
temp = lcase(" " &amp; temp &amp; " ")
pos = instr(temp,".")
if (pos &gt;0) then
GetDomainFromTargetComputer = trim(mid(temp,pos+1))
else
GetDomainFromTargetComputer = ""
end if
end function
'////////////////////////////
function GetNetBIOSNameFromTargetComputer(machinename)
dim pos, temp
temp = machinename
temp = lcase(" " &amp; temp &amp; " ")
pos = instr(temp,".")
if (pos &gt;0) then
GetNetBIOSNameFromTargetComputer = trim(left(temp,pos-1))
else
GetNetBIOSNameFromTargetComputer = ""
end if
end function
'////////////////////////////
function NormalizeDate(x)
dim retval, i, L, c

L = len(x)
for i = 1 to L
c = ucase(mid(x,i,1))
if (instr("/:AMP ",c)=0) then
retval = retval &amp; c
end if
next

NormalizeDate = retval
end function

'////////////////////////////

function GetDateDiff(date1,date2,y,m,d,h,n,s)
'' returns false if date1 &gt; date2

dim x, d1, d2

d1 = date1
d2 = date2

if ( (datediff("yyyy",d1,d2) &lt; 0) or (datediff("m",d1,d2) &lt; 0) or (datediff("d",d1,d2) &lt; 0) or (datediff("h",d1,d2) &lt; 0) or (datediff("n",d1,d2) &lt; 0) or (datediff("s",d1,d2) &lt; 0) ) then
d1 = date2
d2 = date1
GetDateDiff = false ''' date1 not &lt; date2 unexpected
else
d1 = date1
d2 = date2
GetDateDiff = true ''' date1 &lt; date2 as expected
end if


x = datediff("yyyy",d1,d2)
y = x
d1 = dateadd("yyyy",x,d1)
if (datediff("s",d1,d2) &lt; 0) then
d1 = dateadd("yyyy",-1,d1)
y = y -1
end if
WriteLine "years: " &amp; y

x = datediff("m",d1,d2)
m = x
d1 = dateadd("m",x,d1)
if (datediff("s",d1,d2) &lt; 0) then
d1 = dateadd("m",-1,d1)
m = m -1
end if
WriteLine "months behind: " &amp; m

x = datediff("d",d1,d2)
d = x
d1 = dateadd("d",x,d1)
if (datediff("s",d1,d2) &lt; 0) then
d1 = dateadd("d",-1,d1)
d = d -1
end if
WriteLine "days behind: " &amp; d

x = datediff("h",d1,d2)
h = x
d1 = dateadd("h",x,d1)
if (datediff("s",d1,d2) &lt; 0) then
d1 = dateadd("h",-1,d1)
h = h -1
end if
WriteLine "hours behind: " &amp; h

x = datediff("n",d1,d2)
n = x
d1 = dateadd("n",x,d1)
if (datediff("s",d1,d2) &lt; 0) then
d1 = dateadd("n",-1,d1)
n = n -1
end if
WriteLine "minutes behind: " &amp; n

x = datediff("s",d1,d2)
s = x
d1 = dateadd("s",x,d1)
if (datediff("s",d1,d2) &lt; 0) then
d1 = dateadd("s",-1,d1)
s = s -1
end if
WriteLine "seconds behind: " &amp; s

end function

'////////////////////////////
Function IsServiceRunning(servicename)

dim strNamespace, objWMIService, strComputer, colserviceList

strNamespace = "\root\CIMV2"
Set objWMIService = GetObject("winmgmts:\\." &amp; strNameSpace)


On Error Resume Next
strComputer = "."

Dim objServicesCimv2 ' As SWbemServicesEx
Set objServicesCimv2 = GetObject("winmgmts:\\" _
&amp; strComputer &amp; "\root\cimv2")
if err.number = 0 Then

set colserviceList = objServicesCimv2.ExecQuery("select name, StartMode, State from Win32_Service where name = '" &amp; servicename &amp; "'")
dim s
for each s in colservicelist
WriteLine ("service: " &amp; s.name &amp; " " &amp; s.StartMode &amp; " " &amp; s.State)
if ( (lcase(trim(s.state &amp; " ")) = "") or (lcase(trim(s.state &amp; " ")) = "stopped") ) then
IsServiceRunning = false
else
IsServiceRunning = true
end if
exit function
next

Else
wscript.echo Err.Description
End If

wscript.echo "service '" &amp; servicename &amp; "' not found, assuming stopped"
IsServiceRunning = false

end function

'////////////////////////////

Function IsPackageRunning(packagename)

dim strNamespace, objWMIService, strComputer, colserviceList, objRefresher

strNamespace = "\root\CIMV2"
Set objWMIService = GetObject("winmgmts:\\." &amp; strNameSpace)


On Error Resume Next
strComputer = "."

Set objRefresher = createobject("WbemScripting.SWbemRefresher")
Dim objServicesCimv2 ' As SWbemServicesEx
Set objServicesCimv2 = GetObject("winmgmts:\\" _
&amp; strComputer &amp; "\root\cimv2")
if err.number = 0 Then

Dim objRefreshableItem ' As SWbemRefreshableItem
Set objRefreshableItem = _
objRefresher.AddEnum(objServicesCimv2, _
"Win32_PerfFormattedData_AmalgaScriptEngine_AmalgaScriptEngine")

objRefresher.Refresh
objRefresher.Refresh
Dim process
dim counterval
dim retries
for retries = 1 to 10
objRefresher.Refresh
counterval = clng(-1)
For Each process In objRefreshableItem.ObjectSet
if ( lcase(trim(process.name &amp; " ")) = lcase(trim(packagename &amp; " ")) ) then
counterval = process.packagestopped
counterval = clng(counterval)
if err.number &lt;&gt; 0 then
counterval = clng(-1)
end if
WriteLine (process.name &amp; " " &amp; counterval)
if clng(counterval) &lt;&gt; clng(-1) then
IsPackageRunning = (clng(counterval) &lt;&gt; clng(1)) ''' 0 = running, 1 = stopped
exit function
else
WriteLine ("retrying to find the 'Package Stopped' counter")
end if
end if
Next
Next

WriteLine ("'Package Stopped' counter not found for package '" &amp; packagename &amp; "', assuming stopped after retries:" &amp; (retries-1))

IsPackageRunning = false

Else
WriteLine (Err.Description)
WriteLine ("unable to connect to WMI \root\cimv2")
End If

end function

'////////////////////////////
Function GetOldRetVal(strKeyPath, RegValuePrefixName)

GetOldRetVal = ""

Const HKEY_LOCAL_MACHINE = &amp;H80000002
dim strComputer, oReg, strValueName, strValue, arrValueNames
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; _
strComputer &amp; "\root\default:StdRegProv")

If (oReg.EnumKey (HKEY_LOCAL_MACHINE, strKeyPath &amp; "\", arrValueNames) = 0) Then
WriteLine("The registry path exists " &amp; strKeyPath)
Else
WriteLine("The registry path does not exist " &amp; strKeyPath)
exit Function
end if

strValueName = RegValuePrefixName &amp; "_LastUpdatedRetVal"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
strValue = strValue &amp; ""

GetOldRetVal = strValue

WriteLine("Old RetVal =" &amp; strValue)

end function

'////////////////////////////
''------------------------------------------------------------------------------------------</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
</MemberModules>
<Composition>
<Node ID="PackageRunTimeReportProbe">
<Node ID="PassThrough"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>