Print Server - Resume all paused printers

Print_Server___Resume_all_paused_printers (WriteActionModuleType)

Resumes all paused printers

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
Comment{711032F0-A2B3-47D3-ADF5-914700D84B43}

Member Modules:

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

Source Code:

<WriteActionModuleType ID="Print_Server___Resume_all_paused_printers" Comment="{711032F0-A2B3-47D3-ADF5-914700D84B43}" 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"/>
</Configuration>
<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 - Resume all paused printers
' &lt;/name&gt;
' &lt;summary&gt;
' Resumes all paused printers
' &lt;/summary&gt;
'-------------------------------------------------------------------

Option Explicit



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 ThrowScriptError(Byval sMessage, ByVal oErr)
'
' ThrowScriptError :: Creates an event and sends it back to the mom server
'
'
On Error Resume Next
ThrowScriptErrorNoAbort sMessage, oErr
ScriptContext.Quit()
End Function

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 WMIGetObject(ByVal sNamespace)
'
' WMIGetObject :: Returns the WMI object requested.
'
'
Dim oWMI
Dim e
Set e = New Error
On Error Resume Next
Set oWMI = GetObject(sNamespace)
e.Save
On Error Goto 0
If IsEmpty(oWMI) Then
ThrowScriptError "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
End If

Set WMIGetObject = oWMI

End Function

Const RESUME_PRINTER_ERROR_MESSAGE = "Failed to resume printer [{Name}]"

Function GET_RESUME_PRINTER_ERROR_MESSAGE(ByVal sName)
GET_RESUME_PRINTER_ERROR_MESSAGE = Replace(RESUME_PRINTER_ERROR_MESSAGE, "{Name}", sName)
End Function

Const ACCESS_DENIED_ERROR_MESSAGE = "Access denied while resuming printer [{Name}]"

Function GET_ACCESS_DENIED_ERROR_MESSAGE(ByVal sName)
GET_ACCESS_DENIED_ERROR_MESSAGE = Replace(ACCESS_DENIED_ERROR_MESSAGE, "{Name}", sName)
End Function

Sub Main()
Dim oPrinters, oPrinter
Dim oNameSpace
Set oNameSpace = WMIGetObject("winmgmts:\\" &amp; ScriptContext.TargetComputer &amp; "\root\cimv2")

Dim oError
Set oError = New Error

On Error Resume Next
Set oPrinters = oNameSpace.ExecQuery("SELECT * FROM Win32_Printer WHERE Availability = 18 OR ExtendedPrinterStatus = 8",,0)
oError.Save
On Error Goto 0
If oError.Number &lt;&gt; 0 Then
ScriptContext.Echo "Exiting Main because ExecQuery failed."
Exit Sub
End If


Dim lResult

For Each oPrinter In oPrinters
On Error Resume Next
lResult = oPrinter.Resume()
oError.Save
On Error Goto 0

If oError.Number &lt;&gt; 0 Then
ThrowScriptErrorNoAbort GET_RESUME_PRINTER_ERROR_MESSAGE(oPrinter.Name), oError
Else
HandleResult lResult, oPrinter.Name
End If
Next
End Sub

Sub HandleResult(ByVal lResult, ByVal sName)
Select Case lResult
Case 0
Exit Sub
Case 5
ThrowScriptErrorNoAbort GET_ACCESS_DENIED_ERROR_MESSAGE(sName), Err
Case Else
ThrowScriptErrorNoAbort GET_RESUME_PRINTER_ERROR_MESSAGE(sName), Err
End Select
End Sub</Script></Body>
<Language>VBScript</Language>
<Name>Print Server - Resume all paused printers</Name>
<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>