Prev: Specify open file with Excel 2007
Next: Reminder - Microsoft Responds to the Evolution of Community
From: Aziz on 19 May 2010 15:53 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
From: Steve on 19 May 2010 18:44 Aziz wrote: > > 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? > > Option Explicit > > [snip] > > 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 > > [snip] From Visual Basic Scripting Edition, Select Case Statement <http://msdn.microsoft.com/en-us/library/6ef9w614(v=VS.85).aspx>: "If testexpression matches any Case expressionlist expression, the statements following that Case clause are executed up to the next Case clause, or for the last clause, up to End Select. Control then passes to the statement following End Select. If testexpression matches an expressionlist expression in more than one Case clause, *only the statements following the first match are executed.*" (emphasis mine) Download the documentation at <http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9> -- Steve What can be asserted without proof can be dismissed without proof. -Christopher Hitchens
|
Pages: 1 Prev: Specify open file with Excel 2007 Next: Reminder - Microsoft Responds to the Evolution of Community |