Introduction to Printer Logon Scripts for Computers
What people want is a Windows logon script that will assign a printer to a computer - not a user. My advice is,
find another way! At least reconsider your strategy, redefine the problem and see how far you could get assigning a printer to all users or some other way. O.K, you still want a script that will map a printer to a computer. Even though I
don't like the idea, I will give it my best shot, as ever I will tell you all that I know.
Topics for Printer Logon Scripts for Computers
Let us begin with the computer start up sequence. The Windows operating boots up, a logon box appears and is waiting for a username and
password. Meanwhile, any computer logon scripts run, the operating system processes the computer section of the registry. So far so good. However, if you try and run a script that maps a
printer to all the users who logon, it just doesn't work. Even if you try assigning print permissions to the computer - no good. To my logic, this makes sense because otherwise, the operating
system could create a printer for a user, who had been absolutely denied print permission on this particular printer share. By all means experiment, do tell me if I have missed a trick with a
StartUp computer script. However, do be careful, I once got carried away with the scripting, and put a pause statement in a computer script. Nasty. The machine just hung because no-one
could, 'press any key to continue'. Fortunately, I got out of the viscous loop thanks to Remote Desktop.
Four readers ride to my rescueRemember that our goal is to assign a
network printer to a computer, no matter who logs on. The best part of this saga is the positive power of the internet. I have never met these four kind gentlemen, nevertheless they came to
my assistance.
Ben produced a
wonderful example of lateral thinking. He uses the little known loopback method available in Group Policies. What loopback does is turn the computer into a kiosk. No user settings are
applied, only computer setting - this just what we want. In Group Policy navigate to: Administrative Templates\System\Group Policy and select: User Group Policy loopback processing mode, set
it to 'Merge'. Note navigate to the Group Policy folder, not the root of System. Once Ben set the loopback processing, his printer scripts executed, even when he applied them to the computer
and not the user.
The key technique is rundll32 printui.dll,PrintUIEntry. 1) This installs printer quietly rundll32 printui.dll,PrintUIEntry /in /q
/n\\servername\printername 2) This deletes the networked printer from the machine being logged onto, and does so quietly. rundll32 printui.dll,PrintUIEntry /dn /q /n\\servename\printername
3) This Sets the default printer rundll32 printui.dll,PrintUIEntry /y /n\\servername\printername
Warning this script will need adjustment for your environment. For example edit the set pserver = CLTLBXPRN
Warning this script is viscous and will delete all your mapped printers.
@echo off path=c:\util;%path% set pserver=CLTLBXPRN echo Remove All Network Printers.......
con2prt /f echo Show All Available Printers From %pserver%....... net view %pserver%
set /p pname= Enter Printer Name: rundll32 printui.dll,PrintUIEntry /in /n\\%pserver%\%pname% /q set pserver= set pname=
exit
Command Line: rundll32 printui.dll PrintUIEntry /ga /n\\machine\printer Adds a per-machine connection to the client machine. A per-machine connection is a printer configured to be
accessible by all users of the client machine. Normally, when a user adds a printer to a client machine, the printer is visible only to the account used by the person adding the printer. This command must
be run by a local admin of the client machine. The /ga switch is the key component which previous examples lacked. Here is a little research that Guy undertook.1) Check that RUNDLL32 PRINTUI.DLL,PrintUIEntry /? works on your machine, I mention this as it only seems to work on Windows 2003, XP and Windows 2003 machines.
2) Amongst the zillions of switches it seemed that the example: /in - add network printer connection, was the most promising, however I could not get it to work.
3) /y /n Worked to set the default printer. /y /n "Printer Name"
4) /ge /c \\machine also worked.
That was as far as I got, tantalizing and frustrating. And then Ian P. kindly sent in the fruits of his research After some trial and error Ian came up with the following examples that worked The
below adds the printer called PAN_FINANCE to the local PC. The PrintServer on the Domain is PNZ_PS rundll32 printui.dll,PrintUIEntry /in /n"\\print_servername\printername_on_server" eg rundll32
printui.dll,PrintUIEntry /in /n"\\PNZ_PS\PAN_FINANCE_HP4" The below then sets that printer to be the default printer rundll32 printui.dll,PrintUIEntry /y /n"\\print_servername\printername_on_server"
eg rundll32 printui.dll,PrintUIEntry /y /n"\\PNZ_PS\PAN_FINANCE_HP4" Here are Guy's original sources of information: Technet Q189105
Our mission is to create a script which will map a printer to a computer. Who ever logs on will find your choice of printer in their Printers and Faxes folder. At times this project seemed
like mission impossible but thanks to Ben, Pete and Randy, we got the job done.
See Also● Logon Script Home ●
AddWindowsPrinterConnection |