Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for resumeprinting.vbs

(view source code of resumeprinting.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim arrStatus
  4. Dim blnDefault, blnResumed
  5. Dim intJobs, intStatus
  6. Dim colPrinters, colPrintJobs, objItem, objWMIService
  7. Dim strPrinter
  8.  
  9. 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" )
  10.  
  11. With WScript.Arguments
  12. 	If .Count <> 1 Then Syntax
  13. 	If .Named.Exists( "Default" ) Or .Named.Exists( "D" ) Then
  14. 		blnDefault = True
  15. 	Else
  16. 		blnDefault = False
  17. 		If .Unnamed.Count <> 1 Then Syntax
  18. 		strPrinter = .Unnamed( 0 )
  19. 	End If
  20. End With
  21.  
  22. Set objWMIService = GetObject("winmgmts://./root/CIMV2")
  23.  
  24. Set colPrintJobs = objWMIService.ExecQuery( "SELECT * FROM Win32_PrintJob WHERE Name LIKE '" & strPrinter & ", %'", "WQL", 48 )
  25.  
  26. intJobs = 0
  27.  
  28. For Each objItem In colPrintJobs
  29. 	intJobs = intJobs + 1
  30. Next
  31.  
  32. If blnDefault Then
  33. 	Set colPrinters = objWMIService.ExecQuery( "SELECT * FROM Win32_Printer WHERE Default=TRUE", "WQL", 48 )
  34. Else
  35. 	Set colPrinters = objWMIService.ExecQuery( "SELECT * FROM Win32_Printer WHERE DeviceID='" & strPrinter & "'", "WQL", 48 )
  36. End If
  37.  
  38. For Each objItem In colPrinters
  39. 	intStatus = objItem.ExtendedPrinterStatus
  40. 	strPrinter = objItem.DeviceID
  41. 	WScript.Echo "Printer    : " & strPrinter
  42. 	WScript.Echo "Print Jobs : " & intJobs
  43. 	WScript.Echo "Status     : " & arrStatus( intStatus )
  44. 	If objItem.ExtendedPrinterStatus = 8 Then ' Paused
  45. 		WScript.Echo "Resume printing . . ."
  46. 		objItem.Resume()
  47. 		blnResumed = True
  48. 	End If
  49. Next
  50.  
  51. If blnResumed Then
  52. 	Do Until intStatus <> 8
  53. 		WScript.Echo "Wait . . ."
  54. 		WScript.Sleep 1000
  55. 		Set colPrinters = objWMIService.ExecQuery( "SELECT * FROM Win32_Printer WHERE DeviceID='" & strPrinter & "'", "WQL", 48 )
  56. 		For Each objItem In colPrinters
  57. 			intStatus = objItem.ExtendedPrinterStatus
  58. 			WScript.Echo "Status     : " & arrStatus( intStatus )
  59. 		Next
  60. 	Loop
  61. End If
  62.  
  63. Set colPrinters = Nothing
  64. Set objWMIService = Nothing
  65.  
  66.  
  67. Sub Syntax
  68. 	Dim strMsg
  69. 	strMsg = vbCrLf _
  70. 	       & "ResumePrinting.vbs,  Version 1.00" _
  71. 	       & vbCrLf _
  72. 	       & "Resume printing for the specified printer." _
  73. 	       & vbCrLf & vbCrLf _
  74. 	       & "Usage:  CSCRIPT  ResumePrinting.vbs  //NoLogo  printer" _
  75. 	       & vbCrLf & vbCrLf _
  76. 	       & "Where:  ""printer""  is either /D (default printer) or the printer name" _
  77. 	       & vbCrLf _
  78. 	       & "                   (use doublequotes if the printer name contains spaces)" _
  79. 	       & vbCrLf & vbCrLf _
  80. 	       & "Written by Rob van der Woude" & vbCrLf _
  81. 	       & "http://www.robvanderwoude.com"
  82. 	WScript.Echo strMsg
  83. 	Wscript.Quit 1
  84. End Sub
  85.  

page last modified: 2024-04-16; loaded in 0.0069 seconds