How to map a network printer with an IP using Command Line ?

How to map a network printer with an IP using Command Line ?

In smaller companies, often print servers are not used because of economical reasons. On a previous post, I explained how to map a printer shared in a server with CMD.

First its necessary to ensure that the printer is correctly setup, with a static IP address assigned and turned ON.

The next step, is to download the printer driver from the manufacturer’s website, and if necessary extract the contents, search the file with the .INF extension, and open it with your notepad of choice

Search for the name of the driver, in this case “Canon Generic Plus PCL6”. This is very important for the script to work.

The script below has few notes and reminders about how to use it.

REM License: GNU General Public License v2.0
REM Author: Miguel
REM Website: www.techlogist.net
REM Post: https://techlogist.net/batch/how-to-map-a-network-printer-with-an-ip-using-command-line
REM Description: Map a network printer with an IP using Command Line
REM OS/Language/Region: Windows/EN-US
REM Set IP of the printer
set IP=192.168.8.24
REM The printer name can be any you want but without spaces
set Printer_Name=Printer-at-Office
REM The driver name must the one found inside the INF file
set Driver_Name=Driver Name
REM The location of the printer driver .INF file (it can be a remote share)
set INF=\\192.168.8.10\folder\driver_folder\file_x64.inf
REM Finds the correct path for "Printing_Admin_Scripts" (because they change according OS to the language)
set Return_path=%cd%
for /d %%i in (C:\Windows\System32\Printing_Admin_Scripts\*) do cd %%i
set path_folder=%cd%
cd %return_path%
REM The script
rundll32 printui.dll,PrintUIEntry /dl /n "%Printer_Name%" /q
cscript %path_folder%\prnport.vbs -a -r IP%IP% -h %IP% -n 9100 -o raw -me
rundll32 printui.dll,PrintUIEntry /ia /m "%Driver_Name%" /f "%inf%"
rundll32 printui.dll,PrintUIEntry /if /m "%Driver_Name%" /b "%Printer_Name%" /f "%inf%" /r IP%IP%
:EOF
exit