Open In App

Batch Script – Printing / NETPrint Command

Improve
Improve
Like Article
Like
Save
Share
Report

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,

Syntax:

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

Example:

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

# gfg.sh

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,

Syntax:

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

You can specify these options: 

Option Relevance
/dl  Used to delete the local printer
/dn Used to delete network printer connection
/dd Used to delete the printer driver
/e It 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
/if It will Install printer using inf file
/ii  It will Install printer using add printer wizard with an inf file
/il It will Install printer using add printer wizard
/in  Add network printer connection
/ip Install printer using network printer installation wizard
/k It 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
/p Show printer’s properties
/Ss It will load printer settings to a file
/Sr It restores printer settings from a file
/y This 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.

Syntax:

RUNDLL32.EXE PRINTUI.DLL

Example:

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

)


Last Updated : 07 Feb, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads