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 - 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
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
Batch Script - Debugging
Batch Script is a text file that includes a definite amount of operations or commands that are performed in order. It is used in system networks as well as in system administration. It also eliminates a specific repetitive piece of work in various Operating Systems like DOS(Disk Operating System). D
3 min read
Batch Script - Process in Linux
A Batch Script is basically a script having commands which execute sequentially. It helps users to perform repetitive tasks without human or user intervention or input. To automate some tasks like loading processes, and killing processes. Now in this article, we will write a batch script to view all
2 min read
Batch Script - Logging
Batch Script is a file that consists of various commands which need to be sequentially executed. It is not like coding and is not frequently used, in order to communicate with the OS through a command prompt, the user can use Batch Script. The commands are known as Batch commands. Logging refers to
2 min read
Batch Script - String Concatenation
String Concatenation is combining two or more strings to create a new string. For instance, let a string "Good" and take another string "Morning" now by string concatenation i.e. "Good" + "Morning" and we got new string i.e. "Good Morning". This is string concatenation. Let see some examples of stri
2 min read
Batch Processing With Spring Cloud Data Flow
the Spring Cloud Data Flow is an open-source architectural component, that uses other well-known Java-based technologies to create streaming and batch data processing pipelines. The definition of batch processing is the uninterrupted, interaction-free processing of a finite amount of data. Component
3 min read
Bash Scripting - Write Output of Bash Command into Log File
Let there are some situations in which you have to save your output in a file ( generally called log file). Output can be user details ( username, password, Gmail, etc. ), products record ( buying or selling any goods ), or simply any kind of data that you can store in a log file. Let see how to wri
4 min read