(view source code of showprn.bat as plain text)
@ECHO OFF
:: Check Windows version
IF "%OS%"=="Windows_NT" (SETLOCAL) ELSE (GOTO Syntax)
VER | FIND "Windows NT" >NUL && GOTO Syntax
:: Check command line arguments
IF NOT "%~1"=="" IF /I NOT "%~1"=="/A" GOTO Syntax
:: Check if DEVCON.EXE is available and if not, offer to download it
SET DevconAvailable=
SET Download=
DEVCON.EXE /? >NUL 2>&1
IF ERRORLEVEL 1 (
SET DevconAvailable=No
ECHO This batch file requires Microsoft's DEVCON untility.
SET /P Download=Do you want to download it now? [y/N]
)
:: Start download if requested
IF /I "%Download%"=="Y" (
START "DevCon" "http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272"
ECHO.
ECHO Install the downloaded file and make sure DEVCON.EXE is in the PATH.
ECHO Then try again.
)
:: Abort if DEVCON.EXE is not available yet
IF "%DevconAvailable%"=="No" GOTO End
:: List all printers
FOR /F "tokens=1* delims=: " %%A IN ('DEVCON.EXE FindAll ^=Printer ^| FIND.EXE ":"') DO CALL :ShowPrn "%%~A" "%%~B"
ENDLOCAL
GOTO:EOF
:ShowPrn
SETLOCAL
SET HwID="%~1"
SET HwID=%HwID:&= %
SET HwID=%HwID:"= %
FOR %%X IN (%HwID%) DO SET Port=%%X
FOR /F "tokens=1 delims=:." %%X IN ('ECHO.%Port%') DO SET Port=%%X
SET Name=%~2
ECHO.
ECHO Printer name : %Name%
ECHO Printer port : %Port%
ENDLOCAL
GOTO:EOF
:Syntax
ECHO.
ECHO ShowPRN.bat, Version 1.00 for Windows 2000 / XP
ECHO Use DEVCON to list installed printers and their ports
ECHO.
ECHO Usage: SHOWPRN
ECHO.
ECHO Notes: [1] This batch file requires Microsoft's DEVCON.EXE, available at
ECHO http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272
ECHO You will be prompted for download if it isn't found.
ECHO [2] Both active and inactive printers are shown.
ECHO [3] Contrary to its VBScript counterpart, this batch file only lists
ECHO "physical" printers.
ECHO [3] This batch file's VBScript counterpart also lists driver names,
ECHO server and share names.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
page last modified: 2024-04-16; loaded in 0.0053 seconds