Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

VB active directory logon script

Posted on 2006-07-20
6
Medium Priority
?
251 Views
Last Modified: 2008-02-01
Hi,

Please could someone take a look at this logon script for me.  It is basically a logon script to set a users printer based on active directory group membership.
The script seems to run fine but does not do the requested action by mapping a printer when I add my self to any of the groups.  No errors are reported at all.  I added a wscript.echo command to the beginning of the subroutine, however this comment is never echoed suggesting my subroutine sections are not working.
I know this is a big ask as you need to work this script out; I would very much appreciate the help so please could someone tell me where I have gone wrong?

See script bellow
------------------------------------------------------------------------------------------------------------------------------

Option explicit
'On error resume next
Dim wshNet
Dim ADSysInfo
Dim CurrentUser
Dim GroupMember
Dim strGroups
Dim a, b, c
Dim PCompPrinter
Dim PRoomPrinter
Dim ReceptionPrinter
Const PComp = "CN=Post Completion"
Const PRoom = "cn=Post Room"
Const Reception = "cn=Reception"

PCompPrinter = "\\Cs1\nclepostcomp"
PRoomPrinter = "\\Cs1\NCLE - Epson C3000 Colour Laser"
ReceptionPrinter = "\\Cs1\NCLE - RECEPTION HP LaserJet 1100"
Set wshNet = CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" _
    & ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))

Select Case GroupMember
        Case a = Instr(strGroups, PComp)
      PCompsub
        Case b = Instr(strGroups, PRoom)
      PRoomsub
        Case c = Instr(strGroups, Reception)
      Receptionsub
End Select

Sub PCompsub
wshNet.AddWindowsPrinterConnection PCompPrinter
wshNet.SetDefaultPrinter PCompPrinter
End Sub

Sub PRoomsub
wshNet.AddWindowsPrinterConnection PRoomPrinter
wshNet.SetDefaultPrinter PRoomPrinter
End Sub

Sub Receptionsub
wshNet.AddWindowsPrinterConnection ReceptionPrinter
wshNet.SetDefaultPrinter ReceptionPrinter
End Sub

-------------------------------------------------------------------------------------------------------------------------------------------------
0
Comment
Question by:Nael_Shahid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 17147148

Your Case Statement is incorrect. It can't be used as you have it right now.

You would have to do:

If InStr(strGroups, PComp) Then
      PCompSub
ElseIf InStr(strGroups, PRoom) Then
      PRoomSub
ElseIf InStr(strGroups, Reception) Then
      ReceptionSub
End If

The Syntax for Case is as follows:

Select Case <Variant>
      Case "<Value 1>"
            <Statements>
      Case "<Value 2>"
            <Statements>
      Case Else
            <Statements>
End Select

In your original code you're expecting the Case statement to use a function to evaluate something as well so it'll never call the subroutines.

Chris
0
 

Author Comment

by:Nael_Shahid
ID: 17147323
Thanks Chris; I'll test this out and let you know.
0
 

Author Comment

by:Nael_Shahid
ID: 17147767
Hi Chris,

When I first amended this it still did not work; however when I removed "LCase" from "strGroups = LCase(Join(CurrentUser.MemberOf))" it did work.

I wrote this script with the aid of a book so I do not understand what "LCase" does etc...could you explain for me please?

Thanks,
Nael
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 71

Expert Comment

by:Chris Dent
ID: 17152705

LCase simply converts whatever you give it into lower case.

Instead of using LCase it would be better to change it a little like this:

If InStr(1, strGroups, PComp, VbTextCompare) Then
     PCompSub
ElseIf InStr(1, strGroups, PRoom, VbTextCompare) Then
     PRoomSub
ElseIf InStr(1, strGroups, Reception, VbTextCompare) Then
     ReceptionSub
End If

Then it would ignore the case of the letter when trying to do the match - by default it's case sensitive.

Chris
0
 

Author Comment

by:Nael_Shahid
ID: 17152716
Thanks
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 17152762

Pleasure.

Chris
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

648 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question