How can I use a batch file to send a text file or a .doc or similar, to a printer plugged into the computer through a USB port?
Also to get the printer name:
wmic printer get name /value | findstr Name
It will list all printers like:
Name=PDF
Name=Microsoft XPS Document Writer
Name=Fax
And if you know part of the name, you may include it in a variable dynamically with FOR
.
@echo off
for /f "tokens=2 delims==" %%a in (
'wmic printer get name /value ^| findstr PartOfThePrinterName'
) do (
set "printer_name=%%a"
)
REM Also you can remove the FOR command if you want to set the variable as static.
REM ie. "set printer_name=MyPrinterName"
print filename.txt /D:"%printer_name%"
exit /b 0
note the double quotes and no white space after /D:
to be sure it get the right printer.
Another method is to set the default printer and print the document through the notepad.
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%printer_name%"
start /min notepad /P filename.txt