Print Server - State Monitoring

Print_Server___State_Monitoring (WriteActionModuleType)

Reports state for printers and services

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
Comment{49D4321B-8504-4475-9F4C-9A2F3627DB35}

Member Modules:

ID Module Type TypeId RunAs 
RunScriptAction WriteAction System.Mom.BackwardCompatibility.ScriptResponse Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
AlertSeverityOnDoorOpenStatusstring$Config/Parameters/AlertSeverityOnDoorOpenStatus$AlertSeverityOnDoorOpenStatusThe severity of the alert to be raised if a printer returns a status of "Door Open"
AlertSeverityOnJammedStatusstring$Config/Parameters/AlertSeverityOnJammedStatus$AlertSeverityOnJammedStatusThe severity of the alert to be raised if a printer returns a status of "Jammed"
AlertSeverityOnLowPaperStatusstring$Config/Parameters/AlertSeverityOnLowPaperStatus$AlertSeverityOnLowPaperStatusThe severity of the alert to be raised if a printer returns a status of "Low Paper"
AlertSeverityOnLowTonerStatusstring$Config/Parameters/AlertSeverityOnLowTonerStatus$AlertSeverityOnLowTonerStatusThe severity of the alert to be raised if a printer returns a status of "Low Toner"
AlertSeverityOnNoErrorStatusstring$Config/Parameters/AlertSeverityOnNoErrorStatus$AlertSeverityOnNoErrorStatusThe severity of the alert to be raised if a printer returns a status of "No Error"
AlertSeverityOnNoPaperStatusstring$Config/Parameters/AlertSeverityOnNoPaperStatus$AlertSeverityOnNoPaperStatusThe severity of the alert to be raised if a printer returns a status of "No Paper"
AlertSeverityOnNoTonerStatusstring$Config/Parameters/AlertSeverityOnNoTonerStatus$AlertSeverityOnNoTonerStatusThe severity of the alert to be raised if a printer returns a status of "No Toner"
AlertSeverityOnOfflineStatusstring$Config/Parameters/AlertSeverityOnOfflineStatus$AlertSeverityOnOfflineStatusThe severity of the alert to be raised if a printer returns a status of "Offline"
AlertSeverityOnOtherStatusstring$Config/Parameters/AlertSeverityOnOtherStatus$AlertSeverityOnOtherStatusThe severity of the alert to be raised if a printer returns a status of "Other"
AlertSeverityOnOutputBinFullStatusstring$Config/Parameters/AlertSeverityOnOutputBinFullStatus$AlertSeverityOnOutputBinFullStatusThe severity of the alert to be raised if a printer returns a status of "Output Bin Full"
AlertSeverityOnServiceRequestedStatusstring$Config/Parameters/AlertSeverityOnServiceRequestedStatus$AlertSeverityOnServiceRequestedStatusThe severity of the alert to be raised if a printer returns a status of "Service Requested"
AlertSeverityOnUnknownStatusstring$Config/Parameters/AlertSeverityOnUnknownStatus$AlertSeverityOnUnknownStatusThe severity of the alert to be raised if a printer returns a status of "Unknown"

Source Code:

<WriteActionModuleType ID="Print_Server___State_Monitoring" Comment="{49D4321B-8504-4475-9F4C-9A2F3627DB35}" Accessibility="Internal" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>MomBackwardCompatibility!System.Mom.BackwardCompatibility.AlertGenerationSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element name="AlertGeneration" type="AlertGenerationType"/>
<xsd:element name="InvokerType" type="xsd:integer"/>
<xsd:element name="Parameters" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="AlertSeverityOnDoorOpenStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnJammedStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnLowPaperStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnLowTonerStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnNoErrorStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnNoPaperStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnNoTonerStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnOfflineStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnOtherStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnOutputBinFullStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnServiceRequestedStatus" type="xsd:string" minOccurs="0"/>
<xsd:element name="AlertSeverityOnUnknownStatus" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="AlertSeverityOnDoorOpenStatus" Selector="$Config/Parameters/AlertSeverityOnDoorOpenStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnJammedStatus" Selector="$Config/Parameters/AlertSeverityOnJammedStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnLowPaperStatus" Selector="$Config/Parameters/AlertSeverityOnLowPaperStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnLowTonerStatus" Selector="$Config/Parameters/AlertSeverityOnLowTonerStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnNoErrorStatus" Selector="$Config/Parameters/AlertSeverityOnNoErrorStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnNoPaperStatus" Selector="$Config/Parameters/AlertSeverityOnNoPaperStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnNoTonerStatus" Selector="$Config/Parameters/AlertSeverityOnNoTonerStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnOfflineStatus" Selector="$Config/Parameters/AlertSeverityOnOfflineStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnOtherStatus" Selector="$Config/Parameters/AlertSeverityOnOtherStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnOutputBinFullStatus" Selector="$Config/Parameters/AlertSeverityOnOutputBinFullStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnServiceRequestedStatus" Selector="$Config/Parameters/AlertSeverityOnServiceRequestedStatus$" ParameterType="string"/>
<OverrideableParameter ID="AlertSeverityOnUnknownStatus" Selector="$Config/Parameters/AlertSeverityOnUnknownStatus$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="RunScriptAction" TypeID="MomBackwardCompatibility!System.Mom.BackwardCompatibility.ScriptResponse">
<AlertGeneration>$Config/AlertGeneration$</AlertGeneration>
<InvokerType>$Config/InvokerType$</InvokerType>
<Body><Script>
'-------------------------------------------------------------------
' &lt;company&gt;Microsoft Corporation&lt;/company&gt;
' &lt;copyright&gt;Copyright (c) Microsoft Corporation. All rights reserved.&lt;/copyright&gt;
' &lt;name&gt;
' Print Server - State Monitoring
' &lt;/name&gt;
' &lt;summary&gt;
' Reports state for printers and services
' &lt;/summary&gt;
'-------------------------------------------------------------------

Option Explicit

Const PROBLEMSTATE_NOTSET = 0
Const PROBLEMSTATE_GREEN = 1
Const PROBLEMSTATE_GREY = 2
Const PROBLEMSTATE_RED = 3

Const ALERT_SUCCESS = 10
Const ALERT_INFORMATION = 20
Const ALERT_WARNING = 30
Const ALERT_ERROR = 40
Const ALERT_CRITICAL_ERROR = 50
Const ALERT_SECURITY_BREACH = 60
Const ALERT_SERVICE_UNAVAILABLE = 70

Const PRINT_SERVER_CLASS_ID = "Print Server"

Const PRINT_SERVER_SERVER_NAME_ATTRIBUTE_ID = "Server Name"

Const PRINT_SERVER_PRINTERS_COMPONENT_ID = "Printers"
Const PRINT_SERVER_SERVICES_COMPONENT_ID = "Service"




Const wbemCimtypeUseDefault = 0 'Use Default Type CIM type - Custom
Const wbemCimtypeSint16 = 2 'Signed 16-bit integer
Const wbemCimtypeSint32 = 3 'Signed 32-bit integer
Const wbemCimtypeReal32 = 4 '32-bit real number
Const wbemCimtypeReal64 = 5 '64-bit real number
Const wbemCimtypeString = 8 'String
Const wbemCimtypeBoolean = 11 'Boolean value
Const wbemCimtypeObject = 13 'CIM object
Const wbemCimtypeSint8 = 16 'Signed 8-bit integer
Const wbemCimtypeUint8 = 17 'Unsigned 8-bit integer
Const wbemCimtypeUint16 = 18 'Unsigned 16-bit integer
Const wbemCimtypeUint32 = 19 'Unsigned 32-bit integer
Const wbemCimtypeSint64 = 20 'Signed 64-bit integer
Const wbemCimtypeUint64 = 21 'Unsigned 64-bit integer
Const wbemCimtypeDatetime = 101 'Date/time value
Const wbemCimtypeReference = 102 'Reference to a CIM object
Const wbemCimtypeChar16 = 103 '16-bit character

Const ErrAction_None = 0
Const ErrAction_Trace = 1
Const ErrAction_ThrowError = 16
Const ErrAction_Abort = 32
Const ErrAction_ThrowErrorAndAbort = 48

Function GetWMIProperty(oWmi, sPropName, nCIMType, ErrAction)
Dim sValue, oWmiProp

If Not IsValidObject(oWmi) Then
If (ErrAction And ErrAction_ThrowError) = ErrAction_ThrowError Then _
ThrowScriptErrorNoAbort "Accessing property on invalid WMI object.", Err

If (ErrAction And ErrAction_Abort) = ErrAction_Abort Then _
ScriptContext.Quit()

GetWMIProperty = ""
Exit Function
End If

On Error Resume Next
Set oWmiProp = oWmi.Properties_.Item(sPropName)
If Err.Number &lt;&gt; 0 Then
If (ErrAction And ErrAction_ThrowError) = ErrAction_ThrowError Then _
ThrowScriptErrorNoAbort "An error occurred while accessing WMI property: '" &amp; sPropName &amp; "'.", Err

If (ErrAction And ErrAction_Abort) = ErrAction_Abort Then _
ScriptContext.Quit()
End If
On Error Goto 0

If IsValidObject(oWmiProp) Then
sValue = oWmiProp.Value

If IsNull(sValue) Then
'
' If value is null, return blank to avoid any issues
'
GetWMIProperty = ""

Else

Select Case (oWmiProp.CIMType)
Case wbemCimtypeString, wbemCimtypeSint16, wbemCimtypeSint32, wbemCimtypeReal32, wbemCimtypeReal64, wbemCimtypeSint8, wbemCimtypeUint8, wbemCimtypeUint16, wbemCimtypeUint32, wbemCimtypeSint64, wbemCimtypeUint64:
GetWMIProperty = Trim(CStr(sValue))
Case wbemCimtypeBoolean:
If sValue = 1 Or UCase(sValue) = "TRUE" Then
GetWMIProperty = "True"
Else
GetWMIProperty = "False"
End If
Case wbemCimtypeDatetime:

Dim sTmpStrDate

'
' First attempt to convert the whole wmi date string
'
sTmpStrDate = Mid(sValue, 5, 2) &amp; "/" &amp; _
Mid(sValue, 7, 2) &amp; "/" &amp; _
Left(sValue, 4) &amp; " " &amp; _
Mid (sValue, 9, 2) &amp; ":" &amp; _
Mid(sValue, 11, 2) &amp; ":" &amp; _
Mid(sValue, 13, 2)
If IsDate(sTmpStrDate) Then
GetWMIProperty = CDate(sTmpStrDate)
Else

'
' Second, attempt just to convert the YYYYMMDD
'
sTmpStrDate = Mid(sValue, 5, 2) &amp; "/" &amp; _
Mid(sValue, 7, 2) &amp; "/" &amp; _
Left(sValue, 4)
If IsDate(sTmpStrDate) Then
GetWMIProperty = CDate(sTmpStrDate)
Else
'
' Nothing works - return passed in string
'
GetWMIProperty = sValue
End If

End If

Case Else:
GetWMIProperty = ""
End Select
End If
Else

If (ErrAction And ErrAction_ThrowError) = ErrAction_ThrowError Then _
ThrowScriptErrorNoAbort "An error occurred while accessing WMI property: '" &amp; sPropName &amp; "'.", Err

If (ErrAction And ErrAction_Abort) = ErrAction_Abort Then _
ScriptContext.Quit()

GetWMIProperty = ""

End If


If (ErrAction And ErrAction_Trace) = ErrAction_Trace Then _
ScriptContext.Echo " + " &amp; sPropName &amp; " :: '" &amp; GetWMIProperty &amp; "'"

End Function

Class Printer
Private m_oPrinter

Public Sub SetPrinter(ByVal oWMIPrinter)
Set m_oPrinter = oWMIPrinter
End Sub

Public Property Get IsShared()
Const ATTR_SHARED = 8
IsShared = False

If IsNull(m_oPrinter.ServerName) Then
If (m_oPrinter.Attributes And ATTR_SHARED) = ATTR_SHARED Then
IsShared = True
End If
End If
End Property

Public Property Get Name()
Name = GetWMIProperty(m_oPrinter, "Name", wbemCimtypeUseDefault, ErrAction_None)
End Property

Public Property Get DetectedErrorState()
DetectedErrorState = GetWMIProperty(m_oPrinter, "DetectedErrorState", wbemCimtypeUseDefault, ErrAction_None)
End Property

Public Property Get Description()
Dim sDescription
sDescription = GetWMIProperty(m_oPrinter, "Description", wbemCimtypeUseDefault, ErrAction_Trace)
If sDescription = "" Then sDescription = GetWMIProperty(m_oPrinter, "Comment", wbemCimtypeUseDefault, ErrAction_Trace)
Description = sDescription
End Property

Public Property Get DriverName()
DriverName = GetWMIProperty(m_oPrinter, "DriverName", wbemCimtypeUseDefault, ErrAction_Trace)
End Property

Public Property Get Location()
Location = GetWMIProperty(m_oPrinter, "Location", wbemCimtypeUseDefault, ErrAction_Trace)
End Property

Public Property Get Network()
Network = GetWMIProperty(m_oPrinter, "Network", wbemCimtypeUseDefault, ErrAction_Trace)
End Property

Public Property Get PortName()
PortName = GetWMIProperty(m_oPrinter, "PortName", wbemCimtypeUseDefault, ErrAction_Trace)
End Property

Public Property Get ShareName()
ShareName = GetWMIProperty(m_oPrinter, "ShareName", wbemCimtypeUseDefault, ErrAction_Trace)
End Property

Public Property Get ShareServer()
If IsNull(m_oPrinter.ServerName) Then
ShareServer = "\\" &amp; ScriptContext.TargetComputer
Else
ShareServer = GetWMIProperty(m_oPrinter, "ServerName", wbemCimtypeUseDefault, ErrAction_Trace)
End If
End Property

Public Property Get StatusCode()
StatusCode = GetWMIProperty(m_oPrinter, "Availability", wbemCimtypeUseDefault, ErrAction_Trace)
End Property


Public Function StatusCodeToString(ByVal nStatusCode)
If IsNull(nStatusCode) Or Len(nStatusCode) = 0 Then
StatusCodeToString = "Unknown"
Else
Select Case (nStatusCode)
Case 1: StatusCodeToString = "Other"
Case 2: StatusCodeToString = "Unknown"
Case 3: StatusCodeToString = "Idle"
Case 4: StatusCodeToString = "Printing"
Case 5: StatusCodeToString = "Warmup"
Case 6: StatusCodeToString = "Stopped printing"
Case 7: StatusCodeToString = "Offline"
End Select
End If
ScriptContext.Echo " + '" &amp; CStr(nStatusCode) &amp; "' converted to '" &amp; StatusCodeToString &amp; "'."
End Function

Public Function ErrorStateToString(ByVal nErrorState)
If IsNull(nErrorState) Then
ErrorStateToString = "Unknown"
Else
Select Case (nErrorState)
Case 1: ErrorStateToString = "Unknown"
Case 2: ErrorStateToString = "Other"
Case 3: ErrorStateToString = "No Error"
Case 4: ErrorStateToString = "Low Paper"
Case 5: ErrorStateToString = "No Paper"
Case 6: ErrorStateToString = "Low Toner"
Case 7: ErrorStateToString = "No Toner"
Case 8: ErrorStateToString = "Door Open"
Case 9: ErrorStateToString = "Jammed"
Case 10: ErrorStateToString = "Offline"
Case 11: ErrorStateToString = "Service Requested"
Case 12: ErrorStateToString = "Output Bin Full"
Case Else: ErrorStateToString = "No Error"
End Select
End If
ScriptContext.Echo " + '" &amp; nErrorState &amp; "' converted to '" &amp; ErrorStateToString &amp; "'."
End Function
End Class



Class Error
Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile
Public Sub Save()
m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
End Sub
Public Sub Clear()
m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = m_lNumber
End Property
Public Property Get Source()
Source = m_sSource
End Property
Public Property Get Description()
Description = m_sDescription
End Property
Public Property Get HelpContext()
HelpContext = m_sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = m_sHelpFile
End Property
End Class

Function WMIGetInstances(ByVal sNamespace, ByVal sClassName)
'
' WMIGetInstances :: Returns a WMI Instance collection.
'
'
Set WMIGetInstances = Nothing
Const wbemFlagReturnWhenComplete = 0
Const wbemErrFailed = &amp;H80041001
Dim oWMI
Dim e
Set e = New Error
On Error Resume Next
Set oWMI = GetObject(sNamespace)
e.Save
On Error Goto 0
If e.Number &lt;&gt; 0 Then
ThrowScriptErrorNoAbort "Unable to open WMI Namespace '" &amp; sNamespace &amp; "'. Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.", e
Exit Function
End If

On Error Resume Next
Set WMIGetInstances = oWMI.InstancesOf(sClassName, wbemFlagReturnWhenComplete)
e.Save
On Error Goto 0
If (e.Number &lt;&gt; 0) And (e.Number &lt;&gt; wbemErrFailed) Then
ThrowScriptErrorNoAbort "The class name '" &amp; sClassName &amp; "' could not be found. Please check to see if this is a valid WMI class name.", e
Exit Function
End If
End Function

Function CaseInsensitiveStringEquals(ByVal sString1, ByVal sString2)
CaseInsensitiveStringEquals = (StrComp(sString1, sString2, vbTextCompare) = 0)
End Function

''******************************************************************************
' Name: CreateAlert
'
' Purpose: Creates, but does not submit, an alert
'
' Parameters:
' iSeverity - The severity of the alert.
' sName - The name of the alert.
' sDescription - The alert description.
' sRole - The server role
' sInstance - The server role instance for which to issue a state alert.
' sComponent - The component affected
' iProblemState - The problem state
'
Function CreateAlert(ByVal iSeverity, ByVal sName, ByVal sDescription, ByVal sRole, ByVal sInstance, ByVal sComponent, ByVal iProblemState)
Dim oAlert

Set oAlert = ScriptContext.CreateAlert()

oAlert.Name = sName
oAlert.Description = sDescription
oAlert.AlertSource = "Print Server - State Monitoring"
oAlert.AlertLevel = iSeverity

'If there is a role, instance and component specified then this is a state alert
If sRole &lt;&gt; "" And sInstance &lt;&gt; "" And sComponent &lt;&gt; "" Then
oAlert.ProblemState = iProblemState
oAlert.ServerRole = sRole
oAlert.ServerRoleInstance = sInstance
oAlert.Component = sComponent
oAlert.ComponentInstance = ""
End If

Set CreateAlert = oAlert
End Function

''******************************************************************************
' Name: CreateComponentInstanceAlert
'
' Purpose: Creates, but does not submit, an alert
'
' Parameters:
' iSeverity - The severity of the alert.
' sName - The name of the alert.
' sDescription - The alert description.
' sRole - The server role
' sInstance - The server role instance for which to issue a state alert.
' sComponent - The component affected
' sComponentInstance - The component instance affected
' iProblemState - The problem state
'
Function CreateComponentInstanceAlert(ByVal iSeverity, _
ByVal sName, _
ByVal sDescription, _
ByVal sRole, _
ByVal sInstance, _
ByVal sComponent, _
ByVal sComponentInstance, _
ByVal iProblemState)
Dim oAlert

Set oAlert = CreateAlert(iSeverity, sName, sDescription, sRole, sInstance, sComponent, iProblemState)
oAlert.ComponentInstance = sComponentInstance

Set CreateComponentInstanceAlert = oAlert
End Function

Sub SubmitComponentInstanceAlert(ByVal iSeverity, _
ByVal sName, _
ByVal sDescription, _
ByVal sRole, _
ByVal sInstance, _
ByVal sComponent, _
ByVal sComponentInstance, _
ByVal iProblemState)
ScriptContext.Submit CreateComponentInstanceAlert(iSeverity, _
sName, _
sDescription, _
sRole, _
sInstance, _
sComponent, _
sComponentInstance, _
iProblemState)
End Sub

Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4
Const EVENT_TYPE_AUDITSUCCESS = 8
Const EVENT_TYPE_AUDITFAILURE = 16

Function ThrowScriptErrorNoAbort(ByVal sMessage, ByVal oErr)
'
' ThrowScriptError :: Creates an event and sends it back to the mom server
'
'

Dim sErrDescription, sErrNumber
sErrDescription = oErr.Description
sErrNumber = oErr.Number

On Error Resume Next

Dim oScriptErrorEvent

Set oScriptErrorEvent = ScriptContext.CreateEvent()
With oScriptErrorEvent
.EventNumber = 40000
.EventType = EVENT_TYPE_ERROR
.Message = sMessage
.SetEventParameter """Microsoft Windows Print Server"""
.SetEventParameter sMessage
.SetEventParameter sErrDescription
.SetEventParameter sErrNumber
End With
ScriptContext.Submit oScriptErrorEvent
ScriptContext.Echo "ThrowScriptError('" &amp; sMessage &amp; "')"
End Function

Function IsValidObject(ByVal oObject)
IsValidObject = False

If IsObject(oObject) Then
If Not oObject Is Nothing Then
IsValidObject = True
End If
End If
End Function

Dim STATUS_CODE_TO_PARAMETER_MAP
STATUS_CODE_TO_PARAMETER_MAP = Array(Null, _
"AlertSeverityOnUnknownStatus", _
"AlertSeverityOnOtherStatus", _
"AlertSeverityOnNoErrorStatus", _
"AlertSeverityOnLowPaperStatus", _
"AlertSeverityOnNoPaperStatus", _
"AlertSeverityOnLowTonerStatus", _
"AlertSeverityOnNoTonerStatus", _
"AlertSeverityOnDoorOpenStatus", _
"AlertSeverityOnJammedStatus", _
"AlertSeverityOnOfflineStatus", _
"AlertSeverityOnServiceRequestedStatus", _
"AlertSeverityOnOutputBinFullStatus")

Const ALERT_NONE_NAME = "None"
Const ALERT_SUCCESS_NAME = "Success"
Const ALERT_INFORMATION_NAME = "Information"
Const ALERT_WARNING_NAME = "Warning"
Const ALERT_ERROR_NAME = "Error"
Const ALERT_CRITICAL_ERROR_NAME = "Critical Error"
Const ALERT_SECURITY_BREACH_NAME = "Security Breach"
Const ALERT_SERVICE_UNAVAILABLE_NAME = "Service Unavailable"

Function GetAlertInfo(ByVal sAlertLevelName, ByRef lAlertLevel, ByRef lProblemState)
GetAlertInfo = False
Dim aAlertData
aAlertData = Array( _
Array(ALERT_NONE_NAME, ALERT_SUCCESS, PROBLEMSTATE_GREEN), _
Array(ALERT_SUCCESS_NAME, ALERT_SUCCESS, PROBLEMSTATE_RED), _
Array(ALERT_INFORMATION_NAME, ALERT_INFORMATION, PROBLEMSTATE_RED), _
Array(ALERT_WARNING_NAME, ALERT_WARNING, PROBLEMSTATE_RED), _
Array(ALERT_ERROR_NAME, ALERT_ERROR, PROBLEMSTATE_RED), _
Array(ALERT_CRITICAL_ERROR_NAME, ALERT_CRITICAL_ERROR, PROBLEMSTATE_RED), _
Array(ALERT_SECURITY_BREACH_NAME, ALERT_SECURITY_BREACH, PROBLEMSTATE_RED), _
Array(ALERT_SERVICE_UNAVAILABLE_NAME, ALERT_SERVICE_UNAVAILABLE, PROBLEMSTATE_RED) _
)

Const ALERT_LEVEL_NAME_INDEX = 0
Const ALERT_LEVEL_VALUE_INDEX = 1
Const PROBLEM_STATE_INDEX = 2

Dim aInfo
For Each aInfo In aAlertData
If CaseInsensitiveStringEquals(sAlertLevelName, aInfo(ALERT_LEVEL_NAME_INDEX)) Then
lAlertLevel = aInfo(ALERT_LEVEL_VALUE_INDEX)
lProblemState = aInfo(PROBLEM_STATE_INDEX)
GetAlertInfo = True
Exit Function
End If
Next
End Function

Function GetAlertLevelName(ByVal lStatusCode, ByRef sAlertLevelName)
GetAlertLevelName = False
lStatusCode = CLng(lStatusCode)

If lStatusCode = 0 Then
GetAlertLevelName = True
sAlertLevelName = ALERT_NONE_NAME
ElseIf (lStatusCode &gt; 0) And (lStatusCode &lt;= UBound(STATUS_CODE_TO_PARAMETER_MAP)) Then
GetAlertLevelName = True
sAlertLevelName = ScriptContext.Parameters.Get(STATUS_CODE_TO_PARAMETER_MAP(lStatusCode))
End If
End Function

Sub Main()
ScriptContext.Echo "Print Server State Monitoring (" &amp; CStr(Time) &amp; ")"
ScriptContext.Echo "Obtaining State for Printers"
DoPrinterMonitoring()
ScriptContext.Echo "Complete :: Print Server State Monitoring (" &amp; CStr(Time) &amp; ")"
End Sub


Sub DoPrinterMonitoring()
Dim oPrinters, oWMIPrinter
Dim oPrinter
Set oPrinter = New Printer
Set oPrinters = WMIGetInstances("winmgmts:\\" &amp; ScriptContext.TargetComputer &amp; "\root\cimv2", "Win32_Printer")
If Not IsValidObject(oPrinters) Then Exit Sub
For Each oWMIPrinter In oPrinters
oPrinter.SetPrinter oWMIPrinter
If oPrinter.IsShared Then
Dim sPrinterName, nErrorState, sErrorStr
sPrinterName = oPrinter.Name
ScriptContext.Echo " + Shared: '" &amp; sPrinterName &amp; "'"
nErrorState = oPrinter.DetectedErrorState
If nErrorState = 0 Then
For nErrorState = 1 To UBound(STATUS_CODE_TO_PARAMETER_MAP)
sErrorStr = oPrinter.ErrorStateToString(nErrorState)
SubmitPrinterAlert ALERT_SUCCESS, sPrinterName, sErrorStr, PROBLEMSTATE_GREEN
Next
Else
sErrorStr = oPrinter.ErrorStateToString(nErrorState)
Dim lAlertLevel
Dim lProblemState
Dim sAlertLevelName
If GetAlertLevelName(nErrorState, sAlertLevelName) Then
If GetAlertInfo(sAlertLevelName, lAlertLevel, lProblemState) Then
SubmitPrinterAlert lAlertLevel, sPrinterName, sErrorStr, lProblemState
Else
ThrowScriptErrorNoAbort """" &amp; sAlertLevelName &amp; """ is not a valid alert level name", Err
End If
Else
ThrowScriptErrorNoAbort "There is no alert level associated with printer status code " &amp; nErrorState, Err
End If
ScriptContext.Echo " &gt; Detected Error State : '" &amp; sErrorStr &amp; "'"
End If
Else
ScriptContext.Echo " + Not Shared: '" &amp; oPrinter.Name &amp; "'"
End If
Next
End Sub

Sub SubmitPrinterAlert(ByVal lAlertLevel, ByVal sPrinterName, ByVal sErrorStr, ByVal lProblemState)
SubmitComponentInstanceAlert lAlertLevel, _
"Detected Printer Error on [" &amp; sPrinterName &amp; "]", _
sPrinterName &amp; " has error '" &amp; sErrorStr &amp; "'", _
PRINT_SERVER_CLASS_ID, _
ScriptContext.TargetNetbiosComputer, _
PRINT_SERVER_PRINTERS_COMPONENT_ID, _
sPrinterName, _
lProblemState
End Sub</Script></Body>
<Language>VBScript</Language>
<Name>Print Server - State Monitoring</Name>
<Parameters>
<Parameter>
<Name>AlertSeverityOnDoorOpenStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnDoorOpenStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnJammedStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnJammedStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnLowPaperStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnLowPaperStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnLowTonerStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnLowTonerStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnNoErrorStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnNoErrorStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnNoPaperStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnNoPaperStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnNoTonerStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnNoTonerStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnOfflineStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnOfflineStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnOtherStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnOtherStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnOutputBinFullStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnOutputBinFullStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnServiceRequestedStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnServiceRequestedStatus$</Value>
</Parameter>
<Parameter>
<Name>AlertSeverityOnUnknownStatus</Name>
<Value>$Config/Parameters/AlertSeverityOnUnknownStatus$</Value>
</Parameter>
</Parameters>
<ManagementPackId>[Microsoft.Windows.Server.PrintServer,,1.0.0.1]</ManagementPackId>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="RunScriptAction"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>SystemLibrary!System.BaseData</InputType>
</WriteActionModuleType>