Batch Script Printing
Batch Script Printing
Bash script allows to control printing with the help of the
net print command.
The syntax of this command is given below:
print [/d:print_device] [[drive:][path]filename[...]]
print_devicespecifies a print device
For example, the following command will print the example.txt file to the parallel port lpt1.
print c:\example.txt /c /d:lpt1
Command Line Printer Control
The Windows command-line tool can be used to manage most of the Windows configuration. For this purpose, the
RUNDLL32.EXE commands are used.
The syntax is given below:
RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry [option] [@commandfile]
where the options available are the following:
/dlused to delete the local printer
/dnused to delete network printer connection.
/ddused to delete the printer driver.
/eshows printing preferences.
f[file]either inf file or output file.
/F[file]location of an INF file that the INF file specified with
/fmay depend on.
/iainstalls printer driver using inf file.
/idinstalls printer driver using add printer driver wizard.
/ifinstalls printer using inf file.
/iiinstalls printer using add printer wizard with an inf file.
/ilinstalls printer using add printer wizard.
/inadds network printer connection.
/ipinstalls printer using network printer installation wizard.
/kprints test page to specified printer, cannot be combined with command when installing a printer.
/l[path]printer driver source path.
/m[model]printer driver model name.
/odisplay printer queue view.
/pdisplays printer properties.
/Ssstores printer settings into a file.
/Srrestores printer settings from a file.
/ysets printer as the default.
/Xggets printer settings.
/Xssets printer settings.
Testing if a Printer Exists
It may happen that you are connected to a network printer instead of a local printer. In such cases, it is always useful to check for a printer before printing.
The existence of a printer can be evaluated with the help of the
In the following example, we will first set the printer name and set a file name which will hold the settings of the printer. Then
RUNDLL32.EXE PRINTUI.DLL commands will be used to check if the printer actually exists by sending the configuration settings of the file to the file TR-Printers.txt
SET PrinterName = Test Printer
RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry /Xg /n "%PrinterName%" /f "%file%" /q
IF EXIST "%file%" (
ECHO %PrinterName% printer exists
) ELSE (
ECHO %PrinterName% printer does NOT exists