Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for myprn.bat

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

  1. @ECHO OFF
  2. IF NOT "%1"=="" IF /I NOT "%1"=="/Q" IF /I NOT "%1"=="/V" GOTO Syntax
  3.  
  4. SETLOCAL
  5. IF /I "%1"=="/V" (SET ViewCmd=CALL :Driver) ELSE (SET ViewCmd=ECHO)
  6.  
  7. REGEDIT /E %Temp%.\_ListPrn.reg "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers"
  8.  
  9. IF /I "%1"=="/Q" GOTO List
  10. ECHO. 1>&2
  11. ECHO Printers installed on this PC: 1>&2
  12. ECHO. 1>&2
  13. IF /I NOT "%1"=="/V" GOTO List
  14. ECHO.Printer:	Driver: 1>&2
  15. ECHO. 1>&2
  16.  
  17. :List
  18. FOR /F "tokens=7 delims=\" %%a IN ('TYPE %Temp%.\_ListPrn.reg ^| FIND "["') DO FOR /F "tokens=1 delims=]" %%A IN ('ECHO.%%a ^| FIND "]"') DO %ViewCmd% %%A
  19. IF EXIST %Temp%.\_ListPrn.reg DEL %Temp%.\_ListPrn.reg
  20.  
  21. ENDLOCAL
  22. GOTO:EOF
  23.  
  24.  
  25. :Driver
  26. SET Prn=%*
  27. SET Search=%Prn:"=%
  28. IF "%Search:~0,1%"==" " SET Search=%Search:~1%
  29. REGEDIT /E %Temp%.\_ListDrv.reg "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\%Search%"
  30. FOR /F "tokens=1* delims==" %%X IN ('TYPE %Temp%.\_ListDrv.reg ^| FIND /I "Printer Driver"') DO SET Driver=%%Y
  31. SET Driver=%Driver:"=%
  32. ECHO.%Prn%	:	%Driver%
  33. GOTO:EOF
  34.  
  35.  
  36. :Syntax
  37. ECHO.
  38. ECHO MyPRN.bat,  Version 1.00 for Windows NT 4 / 2000
  39. ECHO Display a list of all printers installed on this PC
  40. ECHO.
  41. ECHO Usage:  %~n0  [ /Q ^| /V ]
  42. ECHO         /Q skip header
  43. ECHO         /V display drivers too ^(tab delimited^)
  44. ECHO.
  45. ECHO Note:   Header is displayed in standard error, so it
  46. ECHO         can be discarded using 2^>NUL
  47. ECHO.
  48. ECHO Written by Rob van der Woude
  49. ECHO http://www.robvanderwoude.com
  50.  

page last uploaded: 2017-04-06, 13:33