(view source code of resumeprinting.vbs as plain text)
Option Explicit
Dim arrStatus
Dim blnDefault, blnResumed
Dim intJobs, intStatus
Dim colPrinters, colPrintJobs, objItem, objWMIService
Dim strPrinter
arrStatus = Array( "Script Error", "Other", "Unknown", "Idle", "Printing", "Warmup", "Stopped Printing", "Offline", "Paused", "Error", "Busy", "Not Available", "Waiting", "Processing", "Initialization", "Power Save", "Pending Deletion", "I/O Active", "Manual Feed" )
With WScript.Arguments
If .Count <> 1 Then Syntax
If .Named.Exists( "Default" ) Or .Named.Exists( "D" ) Then
blnDefault = True
Else
blnDefault = False
If .Unnamed.Count <> 1 Then Syntax
strPrinter = .Unnamed( 0 )
End If
End With
Set objWMIService = GetObject("winmgmts://./root/CIMV2")
Set colPrintJobs = objWMIService.ExecQuery( "SELECT * FROM Win32_PrintJob WHERE Name LIKE '" & strPrinter & ", %'", "WQL", 48 )
intJobs = 0
For Each objItem In colPrintJobs
intJobs = intJobs + 1
Next
If blnDefault Then
Set colPrinters = objWMIService.ExecQuery( "SELECT * FROM Win32_Printer WHERE Default=TRUE", "WQL", 48 )
Else
Set colPrinters = objWMIService.ExecQuery( "SELECT * FROM Win32_Printer WHERE DeviceID='" & strPrinter & "'", "WQL", 48 )
End If
For Each objItem In colPrinters
intStatus = objItem.ExtendedPrinterStatus
strPrinter = objItem.DeviceID
WScript.Echo "Printer : " & strPrinter
WScript.Echo "Print Jobs : " & intJobs
WScript.Echo "Status : " & arrStatus( intStatus )
If objItem.ExtendedPrinterStatus = 8 Then ' Paused
WScript.Echo "Resume printing . . ."
objItem.Resume()
blnResumed = True
End If
Next
If blnResumed Then
Do Until intStatus <> 8
WScript.Echo "Wait . . ."
WScript.Sleep 1000
Set colPrinters = objWMIService.ExecQuery( "SELECT * FROM Win32_Printer WHERE DeviceID='" & strPrinter & "'", "WQL", 48 )
For Each objItem In colPrinters
intStatus = objItem.ExtendedPrinterStatus
WScript.Echo "Status : " & arrStatus( intStatus )
Next
Loop
End If
Set colPrinters = Nothing
Set objWMIService = Nothing
Sub Syntax
Dim strMsg
strMsg = vbCrLf _
& "ResumePrinting.vbs, Version 1.00" _
& vbCrLf _
& "Resume printing for the specified printer." _
& vbCrLf & vbCrLf _
& "Usage: CSCRIPT ResumePrinting.vbs //NoLogo printer" _
& vbCrLf & vbCrLf _
& "Where: ""printer"" is either /D (default printer) or the printer name" _
& vbCrLf _
& " (use doublequotes if the printer name contains spaces)" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
Wscript.Quit 1
End Sub
page last modified: 2024-04-16; loaded in 0.0069 seconds