Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for isduplexprinter.bat

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

  1. @ECHO OFF
  2. IF "%~1"=="/?" GOTO Syntax
  3.  
  4. SETLOCAL ENABLEDELAYEDEXPANSION
  5.  
  6. IF "%~1"=="" (
  7. 	FOR /F "tokens=1* delims==" %%A IN ('WMIC.EXE Path Win32_Printer WHERE Default^=TRUE Get Name /Format:value ^| FIND.EXE "="') DO (
  8. 		FOR /F "tokens=1*" %%C IN ("%%~B") DO (
  9. 			SET PrinterName="%%~C"
  10. 		)
  11. 	)
  12. ) ELSE (
  13. 	FOR /F "tokens=1* delims==" %%A IN ('WMIC.EXE Path Win32_Printer WHERE Name^="%~1" Get Name /Format:value ^| FIND.EXE "="') DO (
  14. 		FOR /F "tokens=1*" %%C IN ("%%~B") DO (
  15. 			SET PrinterName="%%~C"
  16. 		)
  17. 	)
  18. )
  19.  
  20. IF NOT DEFINED PrinterName (
  21. 	ECHO Unknown printer name
  22. 	ENDLOCAL
  23. 	EXIT /B -1
  24. )
  25.  
  26. WMIC.EXE Path Win32_Printer WHERE Name^=%PrinterName% Get Capabilities | FINDSTR.EXE /R /C:"[{ ,]3[} ,]" >NUL
  27.  
  28. SET /A RC = 1 - %ErrorLevel%
  29.  
  30. IF "%RC%"=="1" (
  31. 	ECHO Printer %PrinterName% IS duplex capable
  32. ) ELSE (
  33. 	ECHO Printer %PrinterName% is NOT duplex capable
  34. )
  35.  
  36. ENDLOCAL & EXIT /B %RC%
  37.  
  38.  
  39. :Syntax
  40. ECHO.
  41. ECHO IsDuplexPrinter.bat,  Version 1.00
  42. ECHO Check if a printer is capable of duplex ^(two-sided^) printing
  43. ECHO.
  44. ECHO Usage:    IsDuplexPrinter.bat  [ "printer" ]
  45. ECHO.
  46. ECHO Where:    "printer"   is the optional name of the printer to be checked
  47. ECHO                       ^(default: the default printer^)
  48. ECHO.
  49. ECHO Returns:  On screen message stating if the printer is duplex capable.
  50. ECHO           Return code 1 if duplex capable, 0 if not, -1 in case of errors.
  51. ECHO.
  52. ECHO Written by Rob van der Woude
  53. ECHO http://www.robvanderwoude.com
  54.  
  55. EXIT /B -1
  56.  

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