Install Network Printers Via Batch File or Command Line in Windows 7/8 and Server 2008
As a desktop administrator, I like to automate as many tasks as possible. Recently, I needed to automate the installation of network printers in a Windows 7 and Windows Server 2008 environment. After some digging through manuals, I found a solution for installing TCP/IP printers via a batch file. In this tutorial, I will outline the VBS script we will leverage for port creation, and I will also describe the use of rundll32 to install print drivers silently and to create printers.
Modern Windows operating systems such as Windows 7, Windows 8, and Windows Server 2008 have great built-in scripting tools and utilities. However, most users are not aware of these abilities. The guide below includes an example.txt file that will have the generic script included. It also contains an explanation of each step and how to tailor the script to one’s own environment.
The following items are used as examples:
– A computer on the 192.168.1.x network
– An HP Laserjet M603 with static ip address of 192.168.1.200
– A user account that is able to run VBS scripts (administrator or given script abilities)
1.Download the appropriate printer driver for the printer you will be installing. In this example, I am using the HP Universal Print Driver (PCL6) since it works with nearly every HP printer. Be sure to download the newest package at HP’s website.
2. Once downloaded, use 7-zip or other decompression tool to extract the driver packages. We do not actually want to install them. We only want to extract them.
3. Go back to the folder where you extracted the driver package. Now, we need to figure out which .inf file contains the driver we need to install and also what the printer is named in the driver .inf file. To do this we can install the printer on a computer and then go into Printer properties and the Advanced tab to locate the name of the driver. We then just need to find the .inf file that is used.
In our HP example, we will go into the UPD folder and then the PCL folder. Here, we will use the hpcu118c.inf file, and in it, we see HP Universal Printing PCL 6 is the name of the driver.
4. Download and open the example.txt file with Notepad or any text viewer.
Here we will see the following:
cscript %WINDIR%\System32\Printing_Admin_Scripts\en-US\Prnport.vbs -a -r IP_192.168.1.200 -h 192.168.1.200 -o raw -n 9100
rundll32 printui.dll,PrintUIEntry /ia /m "HP Universal Printing PCL 6" /f "C:\printers\HPUPD\PCL\hpcu118c.inf"
rundll32 printui.dll,PrintUIEntry /if /b “HP PRINTER1” /f "C:\printers\HPUPD\PCL\hpcu118c.inf" /r "IP_192.168.1.200” /m "HP Universal Printing PCL 6"
The first line starting w/”cscript” is using a built-in VBS script to create the TCP/IP printer port on the computer that matches the IP address of the printer.
The second line uses rundll32 to install the HP Universal PCL 6 print driver. The name behind /m will vary depending on printer maker/driver and how it is referenced in the proper .inf file. The /f location will also vary depending on where you have files. You can use UNC paths or mapped network drives, too (e.g., /f “\\servername\folder\hpupd\pcl\hpcu118c.inf”).
Finally, the third line uses rundll32 and printui.dll to create the actual printer in the system. The name behind /b is what you will see in Devices and Printers and in programs when you print. The /f will be the same location you used in the previous line, and the port behind /r will be the one you created in the first line.
5. Finally, rename the example.txt to example.bat, and then run it to test. I always suggest testing on a non-production machine, if possible. Your batch file can have as many printers as you want in it. My typical batch files have anywhere from four to 24 printers.
6.Additional automations can include copying the driver folder in the script by using xcopy or robocopy. This also can be used with app deployment suites like SCCM or Zenworks to push printer installations in corporate environments.
View more articles by Jimmy Selix
Follow the reactions below and share your own thoughts.