(view source code of printany.bat as plain text)
@ECHO OFF
:: For Windows NT 4 or later onlyIF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: Localize variablesSETLOCAL
SET PrintCmd=
SET FileType=
SET Temp=%Temp:"=%
:: Command line parsingIF NOT "%~2"=="" GOTO Syntax
IF "%~1"=="" GOTO Syntax
IF "%~n1"=="" GOTO Syntax
IF "%~x1"=="" GOTO Syntax
ECHO."%~1" | FIND "/" >NUL && GOTO Syntax
ECHO."%~1" | FIND "?" >NUL && GOTO Syntax
ECHO."%~1" | FIND "*" >NUL && GOTO Syntax
IF NOT EXIST "%~1" GOTO Syntax
:: Get the file association from the registryFOR /F "tokens=1* delims==" %%A IN ('ASSOC %~x1') DO (
FOR /F "tokens=1 delims==" %%C IN ('FTYPE ^| FIND /I "%%~B"') DO (
CALL :GetPrintCommand %%~C
)):: Check if a print command was foundIF NOT DEFINED PrintCmd GOTO NoAssoc
:: Print the file using the print command we just foundCALL START /MIN "PrintAny" %PrintCmd%
:: DoneGOTO End
:GetPrintCommand:: Get the print command for this file type from the registryFOR /F "tokens=3*" %%D IN ('REG.EXE Query HKCR\%1\shell\print\command /ve 2^>NUL') DO SET PrintCmd=%%E
IF NOT DEFINED PrintCmd GOTO:EOF
:: "Unescape" the commandSET PrintCmd=%PrintCmd:\"="%
SET PrintCmd=%PrintCmd:""="%
SET PrintCmd=%PrintCmd:\\=\%
:: Remove double double quotes in file name if applicableECHO.%PrintCmd% | FINDSTR.EXE /R /C:"\"%%1\"" >NUL && SET PrintCmd=%PrintCmd:"%1"="%%%~1"%
GOTO:EOF
:NoAssocCLS
ECHO.
ECHO Sorry, this batch file works only for known file types with associated
ECHO print commands defined in the registry hive HKEY_CLASSES_ROOT.
ECHO No print command seems to be assiociated with %~x1 files on this computer.
ECHO.
:SyntaxECHO.
ECHO PrintAny.bat, Version 2.01 for Windows 7 and later
ECHO Prints any known file type from the command line
ECHO.
ECHO Usage: PRINTANY file_to_print
ECHO.
ECHO Where: "file_to_print" is the name of the file to be printed
ECHO (use double quotes for long file names)
ECHO.
ECHO Notes: For this batch file to work, the file type's print command has
ECHO to be defined in the registry hive HKEY_CLASSES_ROOT, and that
ECHO print command must NOT use DDE for printing.
ECHO Unfortunately, most Office file types use DDE and hence won't
ECHO print with this batch file.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
:EndIF "%OS%"=="Windows_NT" ENDLOCAL
page last modified: 2025-10-11; loaded in 0.0059 seconds