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

Guy Recommends: Permissions Analyzer – Free Active Directory ToolFree Permissions Analyzer for Active Directory

I like thePermissions Monitor because it enables me to see quickly WHO has permissions to do WHAT.  When you launch this tool it analyzes a users effective NTFS permissions for a specific file or folder, takes into account network share access, then displays the results in a nifty desktop dashboard!

Think of all the frustration that this free utility saves when you are troubleshooting authorization problems for users access to a resource.  Give this permissions monitor a try – it’s free!

Download Permissions Analyser – Free Active Directory Tool

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


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=


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

Guy Recommends SolarWinds’ Free Network MonitorSolarwinds Network Device Monitor

Thus utility makes it easy to check the health of a router or firewall.  Check the real-time performance, and availability statistics, for any device on your network.  Get started with an extensive collection of "out-of-the-box" monitors for popular network devices. Give Network Monitor a whirl – it’s free. Download your free Network Device Monitor

If you need more comprehensive network analysis software:
Download a free trial of NPM (Network Performance Monitor)

Network Printer Example – Kindly Sent By Mark Amaral

Naturally you’ll need to change values such as the IP address and printer information to suit your situation.

<scripts start>
‘ ————————————————————-
‘ Adding an IP

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewPort = objWMIService.Get _

objNewPort.Name = ""
objNewPort.Protocol = 1
objNewPort.HostAddress = ""
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = true

‘ ———————————————————–
‘ Add driver

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True

Set objDriver = objWMIService.Get("Win32_PrinterDriver")

objDriver.Name = " Lexmark E260dn "
objDriver.SupportedPlatform = "Windows XP"
objDriver.Version = "1.0"
objDriver.DriverPath = "\\mcpitsql01\i386"
objDriver.Infname = "\\mcpitsql01\i386\DKAAT940.inf"
intResult = objDriver.AddPrinterDriver(objDriver)

‘ ———————————————————
‘Creating printer
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_

objPrinter.DriverName = "Lexmark E260dn"
objPrinter.PortName = ""
objPrinter.DeviceID = "SharedPrinter"
objPrinter.Location = "Cypress Teller"
objPrinter.Network = True

<script end>

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 more printer logon scripts examples

Logon Script Home   • Printer computer   • Remove printer logon script

AddWindowsPrinterConnection script   • Multiple printers    • Assign Logon Script AD

• EnumPrinterConnections   • SetDefaultPrinter script   • Free Import CSV Tool