VBS Logon Scripts for Windows Printers

Introduction to Printer Logon Scripts

I designed this page as a mini site map for printer logon scripts.  In this section I will help you create VBScripts, which map printers and also set the default printer on Windows networks.

You may be surprised by the sheer variety of Windows logon scripts that control printing.  Along the journey, I will provide examples of VBScript methods.  For example, AddWindowsPrinterConnection, which connects a shared printer to an Windows 7, Vista or even XP clients.

Topics for Printer Windows Logon Scripts


Printer Terminology Check

Microsoft’s printer terminology can be pedantic; nevertheless, we really do need to check the meaning of keywords.  So, to make sure that we are all singing from the same hymn sheet, here is a quick review of printer terms:

Printer: the Icon in the Printer and Faxes folder.  The software interface, which manages the printer properties.  After you run your scripts on the client, navigate, Start Menu,  Control Panel, Printers and see examine any new icons.

Print Device: the hardware.  The physical Epson, HP, or Brother device where you stuff its tray with paper or check its cable connections.

Note: Obviously, the logon script will not install the actual printer device on the print server, I assume that you will do that manually before running the VBscript.

Network Printer: a printer with its own network card.  Usually managed from a print server.  Once it’s shared it behaves like the classic printer.

Printer Driver: I think of the driver as a software ‘jockey’ who rides the printer.  What you need to know, is that Windows 2003 and XP clients, automatically install their own drivers across the network.  With modern clients, there is no scripting for drivers, no user intervention with floppy disks – marvellous.  The only danger is scratching your head and thinking ‘how do script the drivers’, no need – unless you have Window 9x.

Default printer: if a user just hits the print button from inside Word for Windows or similar software, the print job goes to whichever printer is assign as the default.  Good news, you can script the default printer.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Orion performance monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

VBS Printer Methods

VBScripts have three components an object, a method, and a value.  I will show you how to create objNetwork, apply the method and assign a value to your shared network printer.  What gives any scripting language its power is the methods or verbs.  Here is a list of specialist printing methods.

Printer Arguments

Printers verbs have fewer arguments than network drives.  For example AddWindowsPrinterConnection only needs one ‘argument’, the name of the UNC path to the printer.

RemovePrinterConnection rewards your research because it supports the bForce argument, which disconnects the printer – ready or not.  It also has the the bUpdateProfile which saves the changes to the user’s profile.

SetDefaultPrinter and EnumPrinterConnections only needs one ‘argument’ the name of the printer!

Our Mission

Our mission is to create a script, which maps a shared printer, and puts an Icon in the Printers (and Faxes) folder.  The concept is similar to mapping an network drive, but with printers rather than a home directory.  Instead of receiving an extra drive letter in explorer, the users get an extra icon in the Printers folder.

As with so many scripting tasks, these scripts are the equivalent of manual operations, in this case, opening the Printers and Faxes folder, then selecting, Add Printer.

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)

Example – Simple Printer Script with AddWindowsPrinterConnection

Just to get you started here is a simple Windows Logon Script.  Our objective is to connect the client to a shared printer called \\alan\Epson.  Printer scripts have a variety of different methods, here we concentrate on AddWindowsPrinterConnection.

Pre-requisites for Mapping Printers

  1. You need a machine with a shared printer.

Instructions for a simple Printer Logon Script

  1. Copy and paste the script below into notepad.
  2. Change the server name from "\\alan to the name of your print server.
  3. Save the file with .vbs extension e.g. Printers.vbs.
  4. Double click the VBScript and then launch your Printers and Faxes folder.  There should be a new printer icon.

‘ Printers.vbs – Windows Logon Script.
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\alan\Epson."

Learning Points

Note 1:  I do realize that scripts go wrong.  However, with printer scripts, its often the result of ‘over think’, so begin with simple techniques, ideas and syntax.  For instance, this basic script needs no commas.

Note 2: This script conforms to the classic VBScript structure, object, method, and value.  We create objNetwork, apply the AddWindowsPrinterConnection method and assign the value of your shared network printer.

Note 3: There are more comprehensive printer examples here

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

Employ PowerShell for Printer Logon Scripts

 You may have noticed that VBScript is being superseded by PowerShell.  While PowerShell is used mainly for configuring the operating system, it’s possible to employ its cmdlets to add network printers. The technique is to create a ComObject, which can act as a wrapper for familiar VBScript commands. Here is example of PowerShell’s New-Object cmdlet manipulating AddWindowsPrinterConnection:

# PowerShell Printer Logon Script Example
$PSPrint = $(New-Object -ComObject WScript.Network)

You could save these instructions in a .ps1 file.  However, the hard part is executing  this .ps1 file as a logon script.  See more about assigning PowerShell logon scripts.

Printer Logon Scripts Summary

Mapping Printers is a classic job for a Windows logon script.  Take the time to understand the print terminology, then go ahead an copy my scripts and amend them to your circumstances.  Along the journey, take the time to learn more about VBScript objects and particularly methods, for example, AddWindowsPrinterConnection and SetDefaultPrinter.


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