Jump to content

Installing network printers silently - here's how!


Recommended Posts

Folks,

Sorry I haven't contributed in a while, but I'm answering my own question here (from a post weeks ago), and I think others might find this useful.

Adding a TCP/IP printer requires that you have the TCP/IP Port in place first. But there's no easy way to do that via script (that I have found, and I've looked hard). So the easiest way I have found is to set up the ports on your master PC first, then export the following registry branch:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports

This registry branch contains all the details about your TCP/IP ports, so capture the entire branch and save it as a registry file. Then, during your post-install script, add this:

start /high /wait REGEDIT /S printers.reg (name the reg file whatever you like).

Then, after the PC reboots (yes this is necessary), it will be ready to programmatically add network printers and attach them to your newly added TCP/IP ports. I am using a CMD file with the PrintUI command structure, which I'll explain in a moment. Here is an example file adding two printers:

@echo off
ECHO.
ECHO Installing Network Printers ...
ECHO.
ECHO   Printer 1 - Canon ImageRUNNER C3200 Color Copier
start /high /wait rundll32 printui.dll,PrintUIEntry /if /b "ATL - Canon ImageRUNNER C3200" /f c:\Drivers\Printers\C3200\P52KUSAL.inf /r "IP_192.168.10.32" /m "Canon iR C3200-C1 PCL5c" comment "Copy Room"
ECHO.
ECHO   Printer 2 - HP LaserJet 4050N (Accounting)
start /high /wait rundll32 printui.dll,PrintUIEntry /if /b "ATL - HP LaserJet 4050N (Accounting)" /f %windir%\inf\ntprint.inf /r "IP_192.168.10.40" /m "HP LaserJet 4050 Series PCL6" comment "Accounting"

The structure of this command is fairly basic when you take it apart (I have separated the components on different lines for readability, but this should be all on one line):

rundll32 printui.dll,PrintUIEntry /if

/b "printer name you want listed"

/f path and filename of inf file - if long folder names, place in quotes

/r "IP port (expressed as IP_xxx.xxx.xxx.xxx)"

/m "exact spelling of printer listing in INF"

comment "any comment you like"

Notice in the code above I have included a printer whose driver folder and INF file had to be specified (because it's not a printer native to XP), and one printer that it being copied from the XP driver database (the %windir%\inf\ntprint.inf statement tells XP to search it's own database).

You have to make very sure you have the spelling of the printer exactly as it is listed in the INF, otherwise it might not install correctly.

I hope this helps - it works great for me in an environment where I have to install 10 network printers all at once, and I want the clients to print to these printers directly instead of using a print server.

Enjoy! I'll make changes or additions as necessary.

JP

Link to comment
Share on other sites


@alhaddar,

Well, just put the pieces in the right places. What is the IP address you have assigned the printer? Where is the INF file? What is the exact name of the printer in the INF file? And finally, what do you want to call it?

First, set up the IP port on a PC (any PC) that has a connection to the printer, and do a manual install of the printer driver. Note the exact name of the model in the INF file - let's say it's "HP LaserJet 2100 PCL6".

Go into Regedit and export the key I mentioned above, AFTER you set it up manually. That .reg file should be imported during the install process, for instance, during the post-XP installation script (I use a CMD file).

After it reboots, the new PC will be ready to accept the new IP printer, and you can run a second script below. Let's say the IP address you have given the printer is 192.168.1.21.

Let's also assume that the printer driver is not in XP, but you have copied it to a folder beforehand (like during the first install script) - we'll say it's in c:\Install\Printers\HPLJ2100\HP2100.INF. And let's say you want to call it "Al's LaserJet 2100".

You would create a small CMD file that put the pieces in place like so:

@echo off
ECHO.
ECHO Installing Network Printers ...
ECHO.
ECHO   Al's LaserJet 2100 ...
start /high /wait rundll32 printui.dll,PrintUIEntry /if /b "Al's LaserJet 2100" /f c:\Install\Printers\HPLJ2100\HP2100.INF /r "IP_192.168.1.21" /m "HP LaserJet 2100 PCL6"

The order of events is:

1 - XP is installed

2 - XP auto-reboot

3 - you run a post-installation script to install your apps (for example, a CMD file), and in this file you import the .reg file with the IP address

4 - reboot again, called from the CMD file (I use %windir%\system32\shutdown.exe -r -t 90 -c "Initial Install Complete! After reboot, run INSTALL PRINTERS.CMD to install printers." in my CMD

5 - run the Install Printers CMD file you create from the code above. At that point your printer is listed and ready to use.

That's it. I can't make it much easier than that - just copy and paste.

Good luck,

JP

Link to comment
Share on other sites

  • 2 years later...

I'm attempting to automate the installation of the Kyocera FS-2000D driver, and It appears that with Windows XP SP2, when installing a print driver (including WHQL certified) the user is required to select 'Continue Anyway' at the Windows Logo warning.

I have adjusted Driver Signing Options to 'Ignore' (and making the action the system default) as well as configuring the local policy for "Devices: Unsigned Driver Installation Behavior" to "Silently Proceed" and I still receive a warning when installing my driver. :angry:

Anyone know of a way to bypass this?

Link to comment
Share on other sites

Windows XP has scripts for this
Creates, deletes, and lists standard TCP/IP printer ports, in addition to displaying and changing port configuration
[url="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnport.mspx?mfr=true"]Prnport.vbs [/url]

Adds, deletes, and lists printers or printer connections, in addition to setting and displaying the default printer
[url="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnmngr.mspx?mfr=true"]Prnmngr.vbs[/url]

Configures or displays configuration information about a printer
[url="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prncnfg.mspx?mfr=true"]Prncnfg.vbs[/url]

Adds, deletes, and lists printer drivers
[url="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prndrvr.mspx?mfr=true"]Prndrvr.vbs [/url]

Pauses, resumes, cancels, and lists print jobs
[url="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnjobs.mspx?mfr=true"]Prnjobs.vbs [/url]

Prints a test page, pauses or resumes a printer, and clears a printer queue.
[url="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/prnqctl.mspx?mfr=true"]Prnqctl.vbs [/url]


Sample Adding a port and installing a printer (replace %1 with the computer name or remove "-s %1" for local system)
cscript -nologo c:\WINNT\system32\Prnport.vbs -a -s %1 -r IP_192.168.1.2 -h 192.168.1.2 -o raw -n 9100 -me -i 1 -y public
cscript -nologo c:\WINNT\system32\Prnmngr.vbs -a -s %1 -p "HP LaserJet 4000 (2nd Level)" -m "HP LaserJet 4000 Series PCL6" -r "IP_192.168.1.2"

List printers on a system
cscript -nologo c:\WINNT\system32\Prnmngr.vbs -l -s %1

Delete printer
cscript -nologo c:\WINNT\system32\Prnmngr.vbs -d -s %1 -p "HP LaserJet 4000 (2nd Level)"

Delete all printers
cscript c:\WINNT\system32\Prnmngr.vbs -x -s %1

Delete unused drivers
rem cscript c:\WINNT\system32\prndrvr.vbs -x -s %1

The only problem I ran into is creating a port for a shared printer. If a user on MyComp had shared his printer as HPLaserJ I couldn't create the port "\\MyComp \HPLaserJ" using the above. I was able to work around this by stopping the spoller service, creating the registry entry and restarting the spoller service.

NETSVC spooler \\MyComp /stop
NETSVC spooler \\MyComp /stop
reg.exe add "\\MyComp\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" /v "\\MyComp \HPLaserJ" /f
NETSVC spooler \\MyComp /start
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...