Question

VBS Elseif commands help

Asked by: Bowen1973

Hi,  I have got a script that sets up printers on our network.  after setting up the printers on the users machine the script then looks at AD to see which department they are in and should set the default printer to their dept.

I am doing something really wrong as the deafult for the whole company is being set to GBSTORPR11 instead of their relevant printer.

any help/advise appreciated.

(below is the code for the default part)

Dim Department
 
Department = objUser.Department 
 
if objUser.Department = "IT" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR11"
 
elseif objUser.Department = "Purchasing" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR11 RKW"
 
elseif objUser.Department = "Sales" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR09"
 
elseif objUser.Department = "Accounts" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR03"
 
elseif objUser.Department = "QA" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR16"
 
elseif objUser.Department = "Warehouse" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR04"
 
elseif objUser.Department = "Swan" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR14"
 
elseif objUser.Department = "Returns" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR14"
 
elseif objUser.Department = "Dan" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR19"
 
objUser.Department = "Traffic"
net.SetDefaultPrinter "\\svgfp01\GBSTORPR08"
end if

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-24 at 04:36:16ID24676157
Tags

Visual basic

,

VBS Script

,

esleif command

Topics

VB Controls

,

VB Script

,

Windows Batch Scripting

Participating Experts
3
Points
500
Comments
10

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. dynamic colour of cells based on department name
    I have a floor plan that i have knocked up in excel which uses a v lookup to automatically populates the users that sit in these seats. This spread sheet is just basically seat number / department / user In the floor plan that i designed in excel uses 4 cells per seat a...
  2. Separating departments
    Hi, I have a scenario where i need to segregate the various departments of my company so that i have control which department can see which and which cant see any department, who can use internet etc. I am wondering if using routers can achieve this? If yes how? Else what c...
  3. ElseIf statements not working in login script
    I have a login script that I am creating that is working up to the Else If statements. All code works before these statements, but nothing works after. The code completes, but nothing maps after the If statement completes successfully. This is my first go-round with VB. I app...
  4. Group Not Working of Dept
    Hi, The result is right, not group by deptno or dname. SELECT e.ename,d.deptno,d.dname FROM emp e, dept d WHERE e.deptno = d.deptno; GROUP BY d.dname; Output ======================= ENAME DEPTNO DNAME ---------- ---------- -------------- KING 10 ACCOUNTING BLAKE...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: RolandDeschainPosted on 2009-08-24 at 04:49:07ID: 25167372

Use "Select case" instead of elseif, as in attached code.

If still don't work, then the problem is not in the selector clause.

Dim Department
 
Department = objUser.Department 
 
Select case Depatrment
    Case "IT"
        net.SetDefaultPrinter "\\svgfp01\GBSTORPR11"
 
    Case "Purchasing"
        net.SetDefaultPrinter "\\svgfp01\GBSTORPR11 RKW"
 
    Case "Sales"
        net.SetDefaultPrinter "\\svgfp01\GBSTORPR09"
 
    Case "Accounts"
        net.SetDefaultPrinter "\\svgfp01\GBSTORPR03"
 
    Case "QA"
        net.SetDefaultPrinter "\\svgfp01\GBSTORPR16"
 
    Case "Warehouse"
        net.SetDefaultPrinter "\\svgfp01\GBSTORPR04"
 
    Case "Swan"
        net.SetDefaultPrinter "\\svgfp01\GBSTORPR14"
 
    Case "Returns"
        net.SetDefaultPrinter "\\svgfp01\GBSTORPR14"
 
    Case "Dan"
        net.SetDefaultPrinter "\\svgfp01\GBSTORPR19"
 
    Case "Traffic"
        net.SetDefaultPrinter "\\svgfp01\GBSTORPR08"
 
End Select

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:

Select allOpen in new window

 

by: Bowen1973Posted on 2009-08-24 at 08:35:35ID: 25169383

hi, still no joy i'm affraid..

When i replace the 'elseif' for 'case' the printer defaults to the PR03 (the first in the list), when i use the 'elseif' it sets the default as PR11 but if i set my dept as sales instead of IT it doesnt set the default as PR09 as it should.

any ideas??

the full script to remove all network printers, add printers and set deafults is below.

any help/advise is appreciated

' Script to add network printers to workstations and thin clients
 
 
 
' Declare variables and enumerate existing printer connections
 
On Error Resume Next
 
 
 
Set WshShell = WScript.CreateObject("WScript.Shell")
 
Set WshNetwork = WScript.CreateObject("WScript.Network")
 
Set oPrinters = WshNetwork.EnumPrinterConnections
 
 
 
Dim computerName
 
computerName = LCase(WshNetwork.ComputerName)
 
 
 
 
 
' Delete existing connections to network printers
 
 For i = 0 to oPrinters.Count - 1 Step 2
 
           On Error Resume Next
 
	    if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then
 
            	WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true
 
           else WScript.Echo "No network printers found"
 
           end if
 
Next
 
' Add printer connections dependant upon location
 
' Variable to select print server
 
Dim printServer
 
printServer = "SVGFP01"
 
 
 
' VBScript.
Set net = WScript.CreateObject("wscript.network")
 
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR03"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR03 PowerForce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR03 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04 PowerForce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04 Swan"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR05"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR08"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR09"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR10"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11 A3"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11 Powerforce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR13"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR14"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR14 PowerForce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR14 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR16"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR17"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR18"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR19"
 
Dim qQuery, objSysInfo, objuser
Dim Department
 
Department = objUser.Department 
 
if objUser.Department = "IT" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR11"
 
elseif objUser.Department = "Purchasing" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR11 RKW"
 
elseif objUser.Department = "Sales" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR09"
 
elseif objUser.Department = "Accounts" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR03"
 
elseif objUser.Department = "QA" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR16"
 
elseif objUser.Department = "Warehouse" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR04"
 
elseif objUser.Department = "Swan" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR14"
 
elseif objUser.Department = "Returns" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR14"
 
elseif objUser.Department = "Dan" then
net.SetDefaultPrinter "\\svgfp01\GBSTORPR19"
 
objUser.Department = "Traffic"
net.SetDefaultPrinter "\\svgfp01\GBSTORPR08"
end if

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:

Select allOpen in new window

 

by: exx1976Posted on 2009-08-24 at 11:49:22ID: 25171176

First things first..    WOW is that code painful on the eyes!  Here's a cleaned up version we can work with.

I'll continue this post in a moment so I can reference line numbers.

' Script to add network printers to workstations and thin clients
' Declare variables and enumerate existing printer connections
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
computerName = LCase(WshNetwork.ComputerName)
' Delete existing connections to network printers
For i = 0 to oPrinters.Count - 1 Step 2
    if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" Then
    	WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, True
	Else
		WScript.Echo "No network printers found"
	end if
Next
' Add printer connections dependant upon location
' Variable to select print server
printServer = "SVGFP01"
Set net = WScript.CreateObject("wscript.network")
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR03"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR03 PowerForce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR03 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04 PowerForce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR04 Swan"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR05"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR08"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR09"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR10"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11 A3"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11 Powerforce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR11 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR13"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR14"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR14 PowerForce"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR14 RKW"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR16"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR17"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR18"
net.AddWindowsPrinterConnection "\\svgfp01\GBSTORPR19"
Department = objUser.Department 
if objUser.Department = "IT" Then
	net.SetDefaultPrinter "\\svgfp01\GBSTORPR11"
elseif objUser.Department = "Purchasing" Then
	net.SetDefaultPrinter "\\svgfp01\GBSTORPR11 RKW"
elseif objUser.Department = "Sales" Then
	net.SetDefaultPrinter "\\svgfp01\GBSTORPR09"
elseif objUser.Department = "Accounts" Then
	net.SetDefaultPrinter "\\svgfp01\GBSTORPR03"
elseif objUser.Department = "QA" Then
	net.SetDefaultPrinter "\\svgfp01\GBSTORPR16"
elseif objUser.Department = "Warehouse" Then
	net.SetDefaultPrinter "\\svgfp01\GBSTORPR04"
elseif objUser.Department = "Swan" Then
	net.SetDefaultPrinter "\\svgfp01\GBSTORPR14"
elseif objUser.Department = "Returns" Then
	net.SetDefaultPrinter "\\svgfp01\GBSTORPR14"
ElseIf objUser.Department = "Dan" Then
	net.SetDefaultPrinter "\\svgfp01\GBSTORPR19"
	objUser.Department = "Traffic"
	net.SetDefaultPrinter "\\svgfp01\GBSTORPR08"
end If

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:

Select allOpen in new window

 

by: exx1976Posted on 2009-08-24 at 11:53:07ID: 25171217

Ok..   Line 62 - I don't think this is what you were going for, is it?  This code will, if your department is "Dan", change your department to "Traffic", and then SHOULD set the printer to gbstorpro8.

Also, I fail to see where you are getting the information from objuser..  ?  You say this was the full script, yet there is nothing that references the user.  If objuser is not defined, then the default printer on the workstation is never going to get set to anything different than whatever Windows makes it when the printers are added (I don't know if it's the first one created or the last one created, but either way).

Another good way to fnid out where you're getting an error is to remove the  "On Error Resume Next" line from your script.  Then it'll spit out a line number and let you know where to start looking.


HTH,
exx

 

by: Bowen1973Posted on 2009-08-24 at 12:14:37ID: 25171424

Thanks for the Info,  I'm kinda new to the VB script so i have been patching this together from all sorts of places.

Dan is our ops director with a network printer in his office, but the traffic should also have and elseif in front as well (doh!).

i have an MS office VBS script that reads AD by user to set their email signatures and was hoping this script would kinda do the same with knowing what user is logged in read their account in AD read the department and setting the default printer accordingly.

but scripting isnt my strong point...lol...

 

by: exx1976Posted on 2009-08-24 at 12:26:51ID: 25171542

There are numerous ways to get the logged on user.

What I would do, in the interest of consistency, is to open that MS Office VBS and look for the objUser stuff.  You want the line that says something like

Set objUser =

or possibly just  objUser =

Then paste that into your script and see what happens.

I wrote an article on VBS for beginners for use with AD - there's probably a link to it in my profile.  Have a read, it'll probably help you tremendously.

One other thing - most people set printers via Group Membership, not department.  You'd make an AD group for each printer, then put the members in it that should have access to the printer.  Then, secure the printer using that group, and use that group to map users to it via logon script.  Then, the simple act of adding a user to the group means they are allowed to use it, and it's made their default.  I'm sure your Ops Director isn't too happy that his printer is mapped to every computer in the place, and anyone can print to it.  LOL  Also, that would allow you to set Dan's Department to "Operations" so it looks a little cleaner in the GAL (assuming you also use Exchange)..

HTH,
exx

 

by: RobSampsonPosted on 2009-08-24 at 16:38:04ID: 25173557

Hi, you can use the ADSystemInfo object to bind to the user that is currently logged on, so that will allow the script to check the Department of the user.  Also, exx is right about line 62. I assume you actually want another ElseIf there....so that Traffic is treated as a separate department.

Try this.

Regards,

Rob.

' Script to add network printers to workstations and thin clients
' Declare variables and enumerate existing printer connections
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
Set objADSysInfo = CreateObject("ADSystemInfo")
computerName = LCase(WshNetwork.ComputerName)
' Delete existing connections to network printers
For i = 0 to oPrinters.Count - 1 Step 2
    If Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" Then
    	WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), True, True
	Else
		WScript.Echo "No network printers found"
	End If
Next
' Add printer connections dependant upon location
' Variable to select print server
printServer = "SVGFP01"
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR03"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR03 PowerForce"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR03 RKW"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR04"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR04 PowerForce"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR04 RKW"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR04 Swan"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR05"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR08"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR09"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR10"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR11 A3"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR11"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR11 Powerforce"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR11 RKW"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR13"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR14"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR14 PowerForce"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR14 RKW"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR16"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR17"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR18"
WshNetwork.AddWindowsPrinterConnection "\\" & printServer & "\GBSTORPR19"
 
If objUser.Department = "IT" Then
	WshNetwork.SetDefaultPrinter "\\" & printServer & "\GBSTORPR11"
ElseIf objUser.Department = "Purchasing" Then
	WshNetwork.SetDefaultPrinter "\\" & printServer & "\GBSTORPR11 RKW"
ElseIf objUser.Department = "Sales" Then
	WshNetwork.SetDefaultPrinter "\\" & printServer & "\GBSTORPR09"
ElseIf objUser.Department = "Accounts" Then
	WshNetwork.SetDefaultPrinter "\\" & printServer & "\GBSTORPR03"
ElseIf objUser.Department = "QA" Then
	WshNetwork.SetDefaultPrinter "\\" & printServer & "\GBSTORPR16"
ElseIf objUser.Department = "Warehouse" Then
	WshNetwork.SetDefaultPrinter "\\" & printServer & "\GBSTORPR04"
ElseIf objUser.Department = "Swan" Then
	WshNetwork.SetDefaultPrinter "\\" & printServer & "\GBSTORPR14"
ElseIf objUser.Department = "Returns" Then
	WshNetwork.SetDefaultPrinter "\\" & printServer & "\GBSTORPR14"
ElseIf objUser.Department = "Dan" Then
	WshNetwork.SetDefaultPrinter "\\" & printServer & "\GBSTORPR19"
ElseIf objUser.Department = "Traffic"
	WshNetwork.SetDefaultPrinter "\\" & printServer & "\GBSTORPR08"
End If

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:

Select allOpen in new window

 

by: RobSampsonPosted on 2009-08-24 at 16:41:30ID: 25173580

P.S. I have taken the above code from exx's snippet, which will start by removing all network printers, then adding *all* of the printers you have specified to each user.  If that is not what you want, just delete lines 9 through to 16 inclusive, and 21 to 42 inclusive from the code above.

Rob.

 

by: Bowen1973Posted on 2009-08-24 at 17:00:21ID: 25173648

excellent!! that did the trick.  

there was also a 'then' missing from the end as well.

thanks so much for your help, you are both stars...exx i'll have a look at your vb for beginners as well, hopefully it will help me to not make the same mistakes :-)

 

by: RobSampsonPosted on 2009-08-24 at 17:03:02ID: 25173652

Oh yeah! Whoops! Good catch!

Note the key in the code to binding to the current user is:

Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)

Regards,

Rob.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...