Setting up printers is usually done with the "add printer" wizzard. This wizzard (apparently) uses code from a library, printui.dll. With the RUNDLL32 command it is possible to execute code from the dll, thus enabling us to do from the command line anything the Add Printer Wizzard can do, and - even better - create batch processes to set up multiple printers in seconds, and repeat an identical configuration on multiple computers.
With RUNDLL32 PRINTUI.DLL we can
Although there are other ways to connect to shared printers, e.g. through the WSH Network Object : addWindowsPrinterConnection method, RUNDLL32 PRINTUI.DLL may come in handy, e.g. to install a specific driver locally for the shared printer, as in the case where the workstation requires a different driver than the printer server, and there are no alternative drivers available on the server. The printer can then use the already installed driver.
However, we will focus on local printers, e.g. for the automatic setup of a (print) server, a set of workstations that require local printers for whatever reasons, or for local printers that connect directly to a networkprinter through a tcp/ip printerport.
The command to control printer setup from a command line is rundll32 printui.dll,PrintUIEntry . It comes with a long list of switches, which can be consulted at Rob Vanderwoude, Command Line Printer Control, or by typing rundll32 printui.dll,PrintUIEntry /? . The following 2 statements
rundll32 printui.dll,PrintUIEntry /ia /m "AGFA-AccuSet v52.3" /h "Intel" /v "Windows 2000" /f %windir%\inf\ntprint.inf rundll32 printui.dll,PrintUIEntry /if /b "My Printer" /f "%windir%\inf\ntprint.inf" /r "lpt1:" /m "AGFA-AccuSet v52.3"
The printui.dll needs an .inf file to find out what to install for a given printer. By default (and indicated here with the /f switch), this is %windir%\inf\ntprint.inf. This lists the Microsoft provided printer drivers that come with the Windows installation files (and can be seen in GUI when running the Add Printer Wizzard). For other, vendors specific drivers, use /f to point to a vendor provided inf file - presumably on removable media such as CD-ROM, USB stick or floppy disk.
It follows that printers and drivers are thus identified by a string in the inf.file -- e.g. "AGFA-AccuSet v52.3" or "Brother Bubblejet B-100", and that these strings should be used as arguments for the rundll32 printui.dll statement. Therefore, running a batch printer setup would require a list of printers, using names as in %windir%\inf\ntprint.inf, or an extended list of printer string and corresponding path to .inf file, so that a FOR /F statement can feed those to a set of rundll32 printui.dll,PrintUIEntry command.
"AGFA-AccuSet v52.3"; %windir%\inf\ntprint.inf "Brother Bubblejet B-100"; D:\drivers\nl\oem.inf "BPM 500"; \\server25\old\drivers\printers\oem.inf
for /F "delims=;" %%P in (printers.txt) do ( rundll32 printui.dll,PrintUIEntry /ia /m "%%P" /h "Intel" /v "Windows 2000" /f "%%Q" rundll32 printui.dll,PrintUIEntry /if /m "%%P" /r "lpt1:" /b "My Printer" /f "%%Q" )
Share a printer by adding the /Z switch to the rundll32 printui.dll,PrintUIEntry. An 8 character Sharename is generated automatically.
The following statement works to set up a local (logical) printer, pointing to a network printer using tcp/ip. The tcp/ip printer ports need to be configured on the workstation prior to adding the printer, so the command needs to be combined with a command or script to create TCP/IP ports.
rundll32 printui.dll,PrintUIEntry /if /r "IP_18.104.22.168" /b "My Printer" /f %windir%\inf\ntprint.inf /m "HP Laserjet 4000 Series PCL" /Z
In stead of the rundll32 printui.dll,PrintUIEntry /ia statement, you can - on Windows 2003 Server and Windows XP - use prndrvr.vbs as a command to install printer drivers. prnmngr.vbs offers options that can replace the rundll32 printui.dll,PrintUIEntry /if statements used to setup local printers and connect to tcp/ip printer ports. Refer to Scripts to configure printers on Windows 2003 and Windows XP.
and take it frome there ...