Select Case problem

A

Aziz

Hi,

I've been trying to modify this login script fom http://www.rlmueller.net/
to map network shares based on security groups in AD without using lots and
lors of If Then statements. I've tried to convert it to use Select Case but
although it will run the first select case statement and map the I drive, it
doesn't seem to be running any of the others. Any ideas on how to correct
this?

Code is below:


Option Explicit

Dim objNetwork, objSysInfo, strUserDN
Dim objGroupList, objUser, objFSO

Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.userName

' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.
strUserDN = Replace(strUserDN, "/", "\/")

' Bind to the user and computer objects with the LDAP provider.
Set objUser = GetObject("LDAP://" & strUserDN)

Select Case True
Case IsMember (objUser,"SG - IT")
Call MapDrive("I:", "\\flsrvr03\it")

Case IsMember (objUser,"SG - Achievements")
Call MapDrive("G:", "\\flsrvr03\Achievements")

Case IsMember (objUser,"SG - Senior Management")
Call MapDrive("M:", \\flsrvr03\SM)

End Select





' Clean up.
Set objNetwork = Nothing
Set objFSO = Nothing
Set objSysInfo = Nothing
Set objGroupList = Nothing
Set objUser = Nothing

Function IsMember(ByVal objADObject, ByVal strGroup)
' Function to test for group membership.
' objGroupList is a dictionary object with global scope.

If (IsEmpty(objGroupList) = True) Then
Set objGroupList = CreateObject("Scripting.Dictionary")
End If
If (objGroupList.Exists(objADObject.sAMAccountName & "\") = False) Then
Call LoadGroups(objADObject, objADObject)
objGroupList.Add objADObject.sAMAccountName & "\", True
End If
IsMember = objGroupList.Exists(objADObject.sAMAccountName & "\" _
& strGroup)
End Function

Sub LoadGroups(ByVal objPriObject, ByVal objADSubObject)
' Recursive subroutine to populate dictionary object objGroupList.

Dim colstrGroups, objGroup, j

objGroupList.CompareMode = vbTextCompare
colstrGroups = objADSubObject.memberOf
If (IsEmpty(colstrGroups) = True) Then
Exit Sub
End If
If (TypeName(colstrGroups) = "String") Then
' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.
colstrGroups = Replace(colstrGroups, "/", "\/")
Set objGroup = GetObject("LDAP://" & colstrGroups)
If (objGroupList.Exists(objPriObject.sAMAccountName & "\" _
& objGroup.sAMAccountName) = False) Then
objGroupList.Add objPriObject.sAMAccountName & "\" _
& objGroup.sAMAccountName, True
Call LoadGroups(objPriObject, objGroup)
End If
Set objGroup = Nothing
Exit Sub
End If
For j = 0 To UBound(colstrGroups)
' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.
colstrGroups(j) = Replace(colstrGroups(j), "/", "\/")
Set objGroup = GetObject("LDAP://" & colstrGroups(j))
If (objGroupList.Exists(objPriObject.sAMAccountName & "\" _
& objGroup.sAMAccountName) = False) Then
objGroupList.Add objPriObject.sAMAccountName & "\" _
& objGroup.sAMAccountName, True
Call LoadGroups(objPriObject, objGroup)
End If
Next
Set objGroup = Nothing
End Sub

Function MapDrive(ByVal strDrive, ByVal strShare)
' Function to map network share to a drive letter.
' If the drive letter specified is already in use, the function
' attempts to remove the network connection.
' objFSO is the File System Object, with global scope.
' objNetwork is the Network object, with global scope.
' Returns True if drive mapped, False otherwise.

Dim objDrive

On Error Resume Next
If (objFSO.DriveExists(strDrive) = True) Then
Set objDrive = objFSO.GetDrive(strDrive)
If (Err.Number <> 0) Then
On Error GoTo 0
MapDrive = False
Exit Function
End If
If (objDrive.DriveType = 3) Then
objNetwork.RemoveNetworkDrive strDrive, True, True
Else
MapDrive = False
Exit Function
End If
Set objDrive = Nothing
End If
objNetwork.MapNetworkDrive strDrive, strShare
If (Err.Number = 0) Then
MapDrive = True
Else
Err.Clear
MapDrive = False
End If
On Error GoTo 0
End Function
 

My Computer

Top