Batch Script - Printing / NETPrint Command
Last Updated :
07 Feb, 2022
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
)
Similar Reads
Batch Script - Echo Command Batch script is a type of scripting language used in Windows operating systems to automate repetitive tasks, perform system administration functions, and execute a series of commands. The echo command is one of the most commonly used commands in batch scripting, used to display text or messages on t
8 min read
Batch Script - Return code Return codes are the codes returned by programs when they are executed. If the command line is successful, it should return zero; if it is not successful, it should return non-zero. If the test fails, a non-zero value indicates the error number, and the user can attempt to resolve it by navigating t
3 min read
batch command in Linux with Examples batch command is used to read commands from standard input or a specified file and execute them when system load levels permit i.e. when the load average drops below 1.5. Syntax: batch It is important to note that batch does not accepts any parameters. Other Similar Commands: atq: Used to display th
1 min read
Spring Boot with Spring Batch Spring Batch is a lightweight, robust framework used to develop batch processing applications. It provides reusable functionalities that are essential for processing large volumes of data, such as logging, transaction management, job processing, resource management, and scheduling. When integrated w
10 min read
How To Embed Python Code In Batch Script Embedding Python code in a batch script can be very helpful for automating tasks that require both shell commands and Python scripting. In this article, we will discuss how to embed Python code within a batch script. What are Batch Scripts and Python Code?Batch scripts are text files containing a se
4 min read
Batch Script - Input / Output In this article, we are going to learn how to take input from users using Batch Script. Taking User Input:@echo off echo Batch Script to take input. set /p input= Type any input echo Input is: %input% pauseExplanation :The first 'echo' command is used to print a string.In the next line, 'set /p' com
1 min read