Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Batch Script – Printing / NETPrint Command

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

A Bash script is similar to a simple text file that contains a number of commands that the programmer can write in a command line. In Unix-based systems, these commands are used for performing repetitive tasks. A Bash script consists of a bunch of commands, or it may contain elements like loops, functions, conditional constructs, etc. In other words, a Bash script is similar to a computer program that is specifically written in Bash language.

Some of the features of Bash are given below:

  • Bash can be called by using single-character command-line options and also the multi-character command-line options. For example, (-a, -b) is a single-character command-line, and –debugger is a multi-character command-line option.
  • Bash has a set of Key bindings.
  • Bash allows programmers to use one-dimensional arrays by which they can easily work with a set of data.
  • Bash also provides the functionality of control structures. For example, construct the structure, etc.

Bash script allows us to control printing with the help of the NET PRINT command. The syntax of this command is given below,


print  [/E: print_device] [[drive:][path]filename]
print_device: The print device


In this example, the below command will print GeeksforGeeks.txt to the parallel port LPT3.


print E:\GeeksforGeeks.txt /c /d:LPT3

Command Line Printer Control:

Windows command-line tool can be used to handle most of the configuration in windows. For this purpose, PRINTUI.DLL and RUNDLL32.EXE commands are used. The syntax is given below,


RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry [ option ] [ @commandfile ]
option: The operation to be performed

You can specify these options: 

/dl Used to delete the local printer
/dnUsed to delete network printer connection
/ddUsed to delete the printer driver
/eIt shows printing preferences
/f[file] Either output or inf file
/F[file] It signifies the location of an INF file that the INF file
/id Install printer driver using add printer driver wizard
/ia Install printer driver using inf file
/ifIt will Install printer using inf file
/ii It will Install printer using add printer wizard with an inf file
/ilIt will Install printer using add printer wizard
/in Add network printer connection
/ipInstall printer using network printer installation wizard
/kIt is used to print a test page to a particular printer but it cannot be attached to the command when installing a printer
/l[path]Printer driver source path
/m[model] Printer driver model name
/n[name]The printer name
/o It shows printer queue view
/pShow printer’s properties
/SsIt will load printer settings to a file
/SrIt restores printer settings from a file
/yThis will mark the printer as the default
/Xg It returns printer settings
/Xs This will set printer settings.

How to test if a printer exists?

In some of the cases, the device might be connected with the network printer rather than a local printer. In such scenarios, it is always advantageous to check whether you are connected with the required printer before printing any file. To test this, one may use the below command that also controls most of the printer settings.




In this example, we are firstly assigning the printer name and then assigning a file name that holds the settings of the printer. Here, the RUNDLL32.EXE PRINTUI.DLL commands are used to check whether the printer exists by sending the configuration settings of the file to the file GeeksforGeeks.txt

SET myPrinter = Test Printer

SET myFile=%TEMP%\GeeksforGeeks.txt

RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry /Xg /n “%myPrinter%” /f “%myFile%” /q

IF EXIST “%myFile%” (

   ECHO %myPrinter% exists

) ELSE (

   ECHO %myPrinter% do-not exist


My Personal Notes arrow_drop_up
Last Updated : 07 Feb, 2022
Like Article
Save Article
Similar Reads
Related Tutorials