Printers are from hell

Setting Default Printer in Windows 7 with GPO (and a VB Script)

Printers are from hell

Sometimes Printers Just Print What They Want, Where They Want, When They Want

Previously I mentioned using the “Deployed Printers” of GPO’s to push printers to lab machines.  This works great so far but doesn’t solve one problem, the default printer.

While there are lots of options for how to set a default printer, we have the AD architecture to be able to have each lab/area have a specific GPO.   We also have a GPO that covers all the areas.  The higher GPO installs a script (I called it AssignDefaultPrinter-Arguement.vbs) into our standard script location.  This script can be called upon to set a printer as default dynamically.  Here’s the script, before we discuss more.

'  Script to set default printer via passed argument.
'  Taken from
'  Modified by C. Tangora to have a printer passed as an argument.

Option Explicit
Dim objPrinter
Dim objArgs

WScript.Sleep 1000

Set objArgs = Wscript.Arguments
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter objArgs(0)

The script can then be called on individual logon scripts (administered by the GPO for the specific area), without the need to specialize each script.  Since the script is in the same location for all machines, you just call the script and pass the printer you want to have as the default as the argument.  I would suggest using the quotation marks around the argument, as the arguments are separated by spaces.

A test run of this would be for a printer that was setup via the deployed printers, //printserver/LAB100A Color is the server and name of the printer.  To get it to be the default we run ….

AssignDefaultPrinter-Argument.vbs "//printserver/LAB100A Color"

… and in a few seconds (I built in some time to wait for printers to get in place in case they aren’t), the default printer gets assigned.

There may be other ways to skin this cat, and the code could be a bit cleaner, but I am not a big VBScripter, I’m a BASH kind of guy.  If I decided to forgo my UNiX love and dive deeper into Microsoft scripting, I promise to come back and make this cleaner.

Till next time.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s