Hack 52 Set the Default Printer Based on Location

 < Day Day Up > 

figs/moderate.gif figs/hack52.gif

Using a combination of Group Policy and logon scripts, you can easily assign different default printers to different users .

At the college, where I work, we use mandatory profiles for students, who log into Windows XP machines in three different computer labs in a Windows 2000 Active Directory environment. Each lab has its own networked printer, which should be used by students working in that lab. But the profile can have only one default printer set, which obviously wouldn't work, since students in two labs would default to a printer that wasn't in their room.

The Code

Here is the quick and dirty VBScript that solves the problem:

 set net = CreateObject("WScript.Network") workstation=net.computername location=left(workstation,2) printername="" select case location   case "L1"  printername="L1 LaserJet"   case "L2"  printername="L2 LaserJet"   case "L3"  printername="L3 LaserJet" End Select if printername<>"" then net.SetDefaultPrinter(printername) set net = Nothing 

Running the Hack

The script looks at the first two characters of the computer name (this specifies which lab the computer is located in) and then sets the default printer accordingly . If the student is logging on to a computer that's not in one of the labs, the default printer isn't changed. If you name printers differently in your own environment, you might have to customize the script further as needed.

We run this script in our own environment by specifying it as a logon script using Group Policy (so legacy Windows 98 machines ignore it), because all our labs have Windows XP anyway. All our machines also have the necessary drivers installed and configured, and the printers have the same names , so we just have to change the default printer.

Peter Rysavy

 < Day Day Up > 


Windows Server Hacks
Windows Server Hacks
ISBN: 0596006470
EAN: 2147483647
Year: 2004
Pages: 163
Authors: Mitch Tulloch

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net