Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for showprn.bat

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

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF "%OS%"=="Windows_NT" (SETLOCAL) ELSE (GOTO Syntax)
  4. VER | FIND "Windows NT" >NUL && GOTO Syntax
  5.  
  6. :: Check command line arguments
  7. IF NOT "%~1"=="" IF /I NOT "%~1"=="/A" GOTO Syntax
  8.  
  9. :: Check if DEVCON.EXE is available and if not, offer to download it
  10. SET DevconAvailable=
  11. SET Download=
  12. DEVCON.EXE /? >NUL 2>&1
  13. IF ERRORLEVEL 1 (
  14. 	SET DevconAvailable=No
  15. 	ECHO This batch file requires Microsoft's DEVCON untility.
  16. 	SET /P Download=Do you want to download it now? [y/N] 
  17. )
  18.  
  19. :: Start download if requested
  20. IF /I "%Download%"=="Y" (
  21. 	START "DevCon" "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
  22. 	ECHO.
  23. 	ECHO Install the downloaded file and make sure DEVCON.EXE is in the PATH.
  24. 	ECHO Then try again.
  25. )
  26.  
  27. :: Abort if DEVCON.EXE is not available yet
  28. IF "%DevconAvailable%"=="No" GOTO End
  29.  
  30. :: List all printers
  31. FOR /F "tokens=1* delims=: " %%A IN ('DEVCON.EXE FindAll ^=Printer ^| FIND.EXE ":"') DO CALL :ShowPrn "%%~A" "%%~B"
  32.  
  33. ENDLOCAL
  34. GOTO:EOF
  35.  
  36.  
  37. :ShowPrn
  38. SETLOCAL
  39. SET HwID="%~1"
  40. SET HwID=%HwID:&= %
  41. SET HwID=%HwID:"= %
  42. FOR %%X IN (%HwID%) DO SET Port=%%X
  43. FOR /F "tokens=1 delims=:." %%X IN ('ECHO.%Port%') DO SET Port=%%X
  44. SET Name=%~2
  45. ECHO.
  46. ECHO Printer name :  %Name%
  47. ECHO Printer port :  %Port%
  48. ENDLOCAL
  49. GOTO:EOF
  50.  
  51.  
  52. :Syntax
  53. ECHO.
  54. ECHO ShowPRN.bat,  Version 1.00 for Windows 2000 / XP
  55. ECHO Use DEVCON to list installed printers and their ports
  56. ECHO.
  57. ECHO Usage:  SHOWPRN
  58. ECHO.
  59. ECHO Notes:  [1] This batch file requires Microsoft's DEVCON.EXE, available at
  60. ECHO             http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272
  61. ECHO             You will be prompted for download if it isn't found.
  62. ECHO         [2] Both active and inactive printers are shown.
  63. ECHO         [3] Contrary to its VBScript counterpart, this batch file only lists
  64. ECHO             "physical" printers.
  65. ECHO         [3] This batch file's VBScript counterpart also lists driver names,
  66. ECHO             server and share names.
  67. ECHO.
  68. ECHO Written by Rob van der Woude
  69. ECHO http://www.robvanderwoude.com
  70.  

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