Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for resumeprinting.bat

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

  1. @ECHO OFF
  2. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  3.  
  4. SETLOCAL ENABLEDELAYEDEXPANSION
  5.  
  6. IF     "%~1"=="" GOTO Syntax
  7. IF NOT "%~2"=="" GOTO Syntax
  8. ECHO.%* | FIND "?" >NUL && GOTO Syntax
  9.  
  10. IF /I "%~1"=="/D" (
  11. 	SET UseDefaultPrinter=1
  12. ) ELSE (
  13. 	SET UseDefaultPrinter=0
  14. 	SET Printer=%~1
  15. )
  16.  
  17. :: Convert status numbers to descriptions
  18. SET Status_1=Other
  19. SET Status_2=Unknown
  20. SET Status_3=Idle
  21. SET Status_4=Printing
  22. SET Status_5=Warmup
  23. SET Status_6=Stopped Printing
  24. SET Status_7=Offline
  25. SET Status_8=Paused
  26. SET Status_9=Error
  27. SET Status_10=Busy
  28. SET Status_11=Not Available
  29. SET Status_12=Waiting
  30. SET Status_13=Processing
  31. SET Status_14=Initialization
  32. SET Status_15=Power Save
  33. SET Status_16=Pending Deletion
  34. SET Status_17=I/O Active
  35. SET Status_18=Manual Feed
  36.  
  37. SET DeviceID=
  38. SET PrintJobs=0
  39.  
  40. :: Get printer status
  41. IF %UseDefaultPrinter% EQU 0 (
  42. 	FOR /F "tokens=*" %%A IN ('WMIC Path Win32_Printer  WHERE "DeviceID='%Printer%'" Get DeviceID^,ExtendedPrinterStatus /Format:list ^| FIND "="') DO SET %%A
  43. ) ELSE (
  44. 	FOR /F "tokens=*" %%A IN ('WMIC Path Win32_Printer  WHERE "Default='TRUE'" Get DeviceID^,ExtendedPrinterStatus /Format:list ^| FIND "="') DO SET %%A
  45. 	SET Printer=!DeviceID!
  46. )
  47.  
  48. IF NOT DEFINED DeviceID GOTO Syntax
  49.  
  50. :: Get number of printjobs
  51. FOR /F "tokens=*" %%A IN ('WMIC Path Win32_PrintJob WHERE "Name LIKE '%Printer%%%'" Get Name /Format:list 2^>^&1 ^| FIND "="') DO SET /A PrintJobs += 1
  52.  
  53. :: Display the results
  54. ECHO Printer    : %DeviceID%
  55. ECHO Print Jobs : %PrintJobs%
  56. ECHO Status     : !Status_%ExtendedPrinterStatus%!
  57.  
  58. :: Resume if paused
  59. IF %ExtendedPrinterStatus% EQU 8 (
  60. 	ECHO Resume printing . . .
  61. 	WMIC Path Win32_Printer WHERE "DeviceID='%Printer%'" Call Resume >NUL 2>&1
  62. 	FOR /F "tokens=*" %%A IN ('WMIC Path Win32_Printer WHERE "DeviceID='%Printer%'" Get ExtendedPrinterStatus /Format:list ^| FIND "="') DO SET New%%A
  63. )
  64.  
  65. :: Display new status
  66. IF %ExtendedPrinterStatus% EQU 8 (
  67. 	ECHO Status     : !Status_%NewExtendedPrinterStatus%!
  68. )
  69. ENDLOCAL
  70. GOTO:EOF
  71.  
  72.  
  73. :Syntax
  74. ECHO.
  75. ECHO ResumePrinting.bat,  Version 1.00
  76. ECHO Resume printing for the specified printer.
  77. ECHO.
  78. ECHO Usage:  ResumePrinting.bat  printer
  79. ECHO.
  80. ECHO Where:  "printer"  is either /D (default printer) or the printer name
  81. ECHO                    (use doublequotes if it contains spaces)
  82. ECHO.
  83. ECHO Written by Rob van der Woude
  84. ECHO http://www.robvanderwoude.com
  85.  
  86. IF "%OS%"=="Windows_NT" ENDLOCAL & COLOR 00
  87.  

page last uploaded: 2017-08-21, 14:26