Automatic printer installation
Task
If you are working on a network with any more than 5 computers, printer installation can be a bit of a pain! Login scripts can be great for installing printers (and shared drives amongst other things).
Instructions for connecting to a shared printer are quite easy to find, however, if your trying to connect to a printer available on the network (ie with its own network card) thats slightly harder to do – as I found out after it took me pretty much ALL DAY to set up!!!
Explanation
With a network printer, the first thing you need to do is run a command to create a new printer port:
cscript C:\windows\system32\prnport.vbs -a -r PORT_NAME -h IP_ADDRESS -o raw -n 9100
Obviously replace PORT_NAME and IP_ADDRESS with the appropriate.
Next you will need to install the print driver using the following command:
rundll32 printui.dll,PrintUIEntry /ia /m “DRIVER_NAME” /h “intel” /f DRIVER_INF_FILE_PATH /q
Replace driver name with the name of the driver, replace the driver inf file path with the path to the drivers – these must be stored in a shared location on the server and you need to point to the inf file that will come with the drivers.
Next you need to actually install the printer using the following command:
rundll32 printui.dll,PrintUIEntry /if /b “DESCRIPTION” /f “%windir%\inf\ntprint.inf” /q /r “PORT_NAME” /m “DRIVER” /z /u
Give it any description you want, add in the port name you created earlier and add in the driver nam,e that you installed earlier.
All these commands can be run from the command prompt, but the idea is to run them via a login script – I wont go into detail about that, but basically you run the commands from a batch file located on the netlogon share on the server and this is configured (via active directory) to run when a user logs on.
The one snag with this method is that the user needs to be a member of the adminsitrators in order to install “Local” printers – apparently it will work if they are a member of the “power users” group AND they have add/remove printers right – assigned via group policy, HOWEVER, I tried for AGES but could not get this to work – so if anyone manages it that way, please let me know!!
In addition to this I also found a useful set of commands that allows you to save and restore the actual printer defaults – for example, I needed to set the printer to black and white, so I configured the printer on one machine, then ran this command:
RUNDLL32 PRINTUI.DLL,PrintUIEntry /Ss /n PRINTER_NAME /a NETWORK_SAVE_LOCATION/printerX.bin
which backs up all the settings to printerx.bin
Then, when running my logon script, I add this line at the end:
RUNDLL32 PRINTUI.DLL,PrintUIEntry /Sr /q /n PRINTER_NAME /a NETWORK_SAVE_LOCATION\printerX.bin g d
which restores the saved settings to the printer!!
In addition to the above, you can also delete shared printers:
rundll32 printui.dll,PrintUIEntry /dn /q /n\\share\path
Delete local printers:
RUNDLL32 PRINTUI.DLL,PrintUIEntry /dl /q /n PRINTER_NAME
Thanks
novell.com – More information on saving and restoring printer settings.
Microsoft – Microsofts guide to Printui.dll features
Techsupt.winbatch.com – Another guide to printui.dll with examples.