(view source code of pauseprinting.bat as plain text)
@ECHO OFF
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
SETLOCAL ENABLEDELAYEDEXPANSION
IF "%~1"=="" GOTO Syntax
IF NOT "%~2"=="" GOTO Syntax
ECHO.%* | FIND "?" >NUL && GOTO Syntax
IF /I "%~1"=="/D" (
SET UseDefaultPrinter=1
) ELSE (
SET UseDefaultPrinter=0
SET Printer=%~1
)
:: Convert status numbers to descriptions
SET Status_1=Other
SET Status_2=Unknown
SET Status_3=Idle
SET Status_4=Printing
SET Status_5=Warmup
SET Status_6=Stopped Printing
SET Status_7=Offline
SET Status_8=Paused
SET Status_9=Error
SET Status_10=Busy
SET Status_11=Not Available
SET Status_12=Waiting
SET Status_13=Processing
SET Status_14=Initialization
SET Status_15=Power Save
SET Status_16=Pending Deletion
SET Status_17=I/O Active
SET Status_18=Manual Feed
SET DeviceID=
SET PrintJobs=0
:: Get printer status
IF %UseDefaultPrinter% EQU 0 (
FOR /F "tokens=*" %%A IN ('WMIC Path Win32_Printer WHERE "DeviceID='%Printer%'" Get DeviceID^,ExtendedPrinterStatus /Format:list ^| FIND "="') DO SET %%A
) ELSE (
FOR /F "tokens=*" %%A IN ('WMIC Path Win32_Printer WHERE "Default='TRUE'" Get DeviceID^,ExtendedPrinterStatus /Format:list ^| FIND "="') DO SET %%A
SET Printer=!DeviceID!
)
IF NOT DEFINED DeviceID GOTO Syntax
:: Get number of printjobs
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
:: Display the results
ECHO Printer : %DeviceID%
ECHO Print Jobs : %PrintJobs%
ECHO Status : !Status_%ExtendedPrinterStatus%!
:: Pause if not paused
IF %ExtendedPrinterStatus% NEQ 8 (
ECHO Pause printing . . .
WMIC Path Win32_Printer WHERE "DeviceID='%Printer%'" Call Pause >NUL 2>&1
FOR /F "tokens=*" %%A IN ('WMIC Path Win32_Printer WHERE "DeviceID='%Printer%'" Get ExtendedPrinterStatus /Format:list ^| FIND "="') DO SET New%%A
)
:: Display new status
IF %ExtendedPrinterStatus% NEQ 8 (
ECHO Status : !Status_%NewExtendedPrinterStatus%!
)
ENDLOCAL
GOTO:EOF
:Syntax
ECHO.
ECHO PausePrinting.bat, Version 1.00
ECHO Pause printing for the specified printer.
ECHO.
ECHO Usage: PausePrinting.bat printer
ECHO.
ECHO Where: "printer" is either /D (default printer) or the printer name
ECHO (use doublequotes if it contains spaces)
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
IF "%OS%"=="Windows_NT" ENDLOCAL & COLOR 00
page last modified: 2024-04-16; loaded in 0.0055 seconds