Nael_Shahid
asked on
VB active directory logon script
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.Netw ork")
Set ADSysInfo = CreateObject("ADSystemInfo ")
Set CurrentUser = GetObject("LDAP://" _
& ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.Mem berOf))
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.AddWindowsPrinterCo nnection PCompPrinter
wshNet.SetDefaultPrinter PCompPrinter
End Sub
Sub PRoomsub
wshNet.AddWindowsPrinterCo nnection PRoomPrinter
wshNet.SetDefaultPrinter PRoomPrinter
End Sub
Sub Receptionsub
wshNet.AddWindowsPrinterCo nnection ReceptionPrinter
wshNet.SetDefaultPrinter ReceptionPrinter
End Sub
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
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.Netw
Set ADSysInfo = CreateObject("ADSystemInfo
Set CurrentUser = GetObject("LDAP://" _
& ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.Mem
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.AddWindowsPrinterCo
wshNet.SetDefaultPrinter PCompPrinter
End Sub
Sub PRoomsub
wshNet.AddWindowsPrinterCo
wshNet.SetDefaultPrinter PRoomPrinter
End Sub
Sub Receptionsub
wshNet.AddWindowsPrinterCo
wshNet.SetDefaultPrinter ReceptionPrinter
End Sub
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Chris,
When I first amended this it still did not work; however when I removed "LCase" from "strGroups = LCase(Join(CurrentUser.Mem berOf))" 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
When I first amended this it still did not work; however when I removed "LCase" from "strGroups = LCase(Join(CurrentUser.Mem
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
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
ASKER
Thanks
Pleasure.
Chris
ASKER