Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for showprnt.bat

(view source code of showprnt.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 header
  31. ECHO Printer name:	Port:
  32.  
  33. :: List all printers
  34. FOR /F "tokens=1* delims=: " %%A IN ('DEVCON.EXE FindAll ^=Printer ^| FIND.EXE ":"') DO CALL :ShowPrn "%%~A" "%%~B"
  35.  
  36. ENDLOCAL
  37. GOTO:EOF
  38.  
  39.  
  40. :ShowPrn
  41. SETLOCAL
  42. SET HwID="%~1"
  43. SET HwID=%HwID:&= %
  44. SET HwID=%HwID:"= %
  45. FOR %%X IN (%HwID%) DO SET Port=%%X
  46. FOR /F "tokens=1 delims=:." %%X IN ('ECHO.%Port%') DO SET Port=%%X
  47. SET Name=%~2
  48. ECHO %Name%	%Port%
  49. ENDLOCAL
  50. GOTO:EOF
  51.  
  52.  
  53. :Syntax
  54. ECHO.
  55. ECHO ShowPRNT.bat,  Version 1.00 for Windows 2000 / XP
  56. ECHO Use DEVCON to list installed printers and their ports in tab delimited format
  57. ECHO.
  58. ECHO Usage:  SHOWPRNT
  59. ECHO.
  60. ECHO Notes:  [1] This batch file requires Microsoft's DEVCON.EXE, available at
  61. ECHO             http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272
  62. ECHO             You will be prompted for download if it isn't found.
  63. ECHO         [2] Both active and inactive printers are shown.
  64. ECHO         [3] Contrary to its VBScript counterpart, this batch file only lists
  65. ECHO             "physical" printers.
  66. ECHO         [3] This batch file's VBScript counterpart also lists driver names,
  67. ECHO             server and share names.
  68. ECHO.
  69. ECHO Written by Rob van der Woude
  70. ECHO http://www.robvanderwoude.com
  71.  

page last uploaded: 2017-07-06, 12:37