Logon Scripts

VBS Printer Logon Scripts for Computers

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

 ♦

Fundamental problem mapping a printer to a computer

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 rescue

Remember 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 Wilson - Group Policy LoopbackUser Group Policy loopback processing mode Printer Logon Scripts for computers

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.

Pete Roper sent in printui.dll commands

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

Randy Schuman kindly sent in this script.

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
 

Guy Recommends: SolarWinds LANSurveyorSolarwinds LANSurveyor

LANSurveyor will produce a neat diagram of your network topology.  But that's just the start; LANSurveyor can create an inventory of the hardware and software of your machines and network devices.  Other neat features include dynamic update for when you add new devices to your network.  I also love the ability to export the diagrams to Microsoft Visio.

Finally, Guy bets that if you take a free trial of LANSurveyor then you will find a device on your network that you had forgotten about, or someone else installed without you realizing!

Download a Free Trial of LANSurveyor

Kim Øystein Næss - Improvement by adding /ga

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

Printer Logon Scripts Summary

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.


Download my Logon Script eBook for only $6.25

Logon ScriptThe extra features you get in your eBook include, more pages full of detailed examples.  Also, ten 'how to...' sections, with screen shots showing which menus to use.  Go for Guy's eBook - and get a printable version with copy enabled and no expiry date.

  Jumbo Script 7 Package

See Also

Logon Script Home  ● AddWindowsPrinterConnection

 *


Google

Web  This website

Review of Orion NPMGuy Recommends: Orion's Network Performance Monitor (NPM)

Orion NPM is designed for detecting network outages.

Network-centric views (screenshot) make it easy to see what's working, and what needs your attention.

Download your free trial of Orion's network performance monitor

 

Home Copyright © 1999-2009 Computer Performance LTD All rights reserved

Please report a broken link, or an error.