Creating printers with a script
Posted on 2008-10-09
I am looking to create printers using a script on logon. The goal is to have specific printers for certain user groups on 4 terminal servers. The users connect to these servers through both a Citrix web interface and remote desktop. We would like to have some of the printers created as a connection to a network printer, and others as a local printer with the port set to the network share. This is mostly for naming reasons, so people can see 'Printer1' rather than '\\server2\Printer1' which confuses them.
Basically the problem is that I create a printer on the terminal server on one account, and it doesn't show up on any other user accounts. We need an automated way to ensure that everyone gets the printers they need.
In other words what I want is say Bob in accounting to have the following printers:
Printer1 which is a local printer with it's port set at \\server2\Printer1
\\station1\labelprinter a normal network share printer
But then I want Susie in sales to have totally different printers, along the same format.
I have tried doing this multiple ways with both rundll32 printui.dll,PrintUIEntry and cscript prnmngr.vbs commands.
Example of some rundll32 commands I tried:
rundll32 printui.dll,PrintUIEntry /dl /n "Testing" /q
rundll32 printui.dll,PrintUIEntry /if /b "Testing" /f %windir%\inf\ntprint.inf /r "\\server2\Testing" /m "Brother HL-5140 series" /u
rundll32 printui.dll,PrintUIEntry /in /n \\bob\label /q
But then this method ran into the problem that it will recreate the printer every logon, so it must be deleted before being created. It also has the problem that even though I used the silent switch, it still will show the user an error if it cannot find a network printer. And sometimes it tries to create the new printer before the old one is deleted (even though the delete comes first in the script) and I end up with Printer1 (Copy 1). I do like however that this method allows me to create printers on a per machine basis.
Then I tried cscript prnmngr.vbs to acheive my goal. Here are some examples of what I did:
cscript prnmngr.vbs -a -p "CopyRoomXerox" -m "Xerox WorkCentre 4150" -r "\\server2\CopyRoomXerox"
cscript prnmngr.vbs -ac -p "\\bob\label"
This method had the benefit of not creating additional copies of printers that already exist, or showing error messages to the user. But it doesn't allow per-machine creation or as much customization as the rundll32 did.
I was considering creating seperate .bat files for each group of printers and adding them to people's Active Directory user profile logon script. But then this would add the printers on any computer they log into on the network. Plus, I realized that the scripts fail because the users are not administrators and cannot add printers.
How can I acheive my goal ? I've seen some things about creating a vbs script myself, but I don't know anything about how to program that or if it would even work for all the things I want. And are there any graphical interfaces for doing this? It seems wierd that microsoft allows you to add a printer in 'Printers and Faxes' but there is no way to make it on all user accounts (other than copying that profile to 'Default User' and deleting all user accounts on that machine.)
500 points for anyone that can provide a way to accomplish all of these things.