Login | |
|
 |
probl. network drivemapping based on security group in AD - 7/24/2008 1:02:20 AM
|
|
 |
|
| |
fkonings
Posts: 1
Score: 0
Joined: 7/24/2008
Status: offline
|
Hello There, Hopefully someone can help me? I'm building a "simple" logon script for a Windows 2003 domain. One part of it looks if a user is member of a certain Security group and maps a network drive when this case is True. It doesn't work, i tried several things but still no result In Active Directory there are more layers of OU folders. In one of those OU folder are the security Groups (for mapping drives) - - - - - - - - - - example op script part that doesnt work - - - - - - - Dim strDriveLetter, strRemotePath Dim objNetwork, objShell Dim CheckDrive, AlreadyConnected, intDrive Dim IsMember, strUser Set objShell = CreateObject("WScript.Shell") Set objNetwork = CreateObject("WScript.Network") Set CheckDrive = objNetwork.EnumNetworkDrives() ' ' ' ' (some pieces left out here) ' Dim strUserName Set objNetwork = WScript.CreateObject("WScript.Network") strUserName = objNetwork.UserName objNetwork.MapNetworkDrive strDriveLetter, strRemotePath _ & "\" & strUserName ' ' ' ' drivemapping for sec grp GG-IN-USERS IsMember = False dim objGGIN set objGGIN = GetObject("WinNT://domain-name/GG-IN-Users") For Each User in objGGIN.members if User.Name = strUser then isMember1 = True end if next if IsMember1 = True then objNetwork.MapNetworkDrive "I:", "\\server\share1" end if IsMember = False ' drivemapping for group GG-LE-Users dim objGGLE set objGGLE = GetObject("WinNT://domain name/GG-LE-Users") For Each User in objGGLE.members if User.Name = strUser then isMember = True end if next if IsMember = True then objNetwork.MapNetworkDrive "I:", "\\server1\data" objNetwork.MapNetworkDrive "J:", "\\server1\data2" end if IsMember = False ' drivemapping for sec group GG-GE-Users dim objGGGE set objGGGE = GetObject("WinNT://domain name/GG-GE-Users") For Each User in objGGGE.members if User.Name = strUser then isMember = True end if next if IsMember = True then objNetwork.MapNetworkDrive "L:", \\server\share " end if IsMember = False - - - - - - - - - - - - - - allready tried a few things like one for Each ... end if line tried more IsMember's and strUser's with no result Tried to look with msgbox when the status is True or False struser is sometimes empy or sometimes includes the username, but that could be a typ fault whilst testing ISmember is false in the beginning but after "if user.name = strUser then" it is True. Even if the user doesnt exist in the Securitu Group At the moment there are using Kix32 in this company with the samen kind of script and this is working so i shoudnt be an Active Dir problem. I just want to replace this Kix32 script with a VBscript. Everything is working except for this group security "rule" can anyone help, or have a suggestion for it? selecting in base of OU folder would also be an option in stead of Security Group, but i dont know how. Thanks in advance Freek
|
|
| |
|
|
|
 |
RE: probl. network drivemapping based on security group... - 7/26/2008 4:11:35 PM
|
|
 |
|
| |
fosterr_2000
Posts: 115
Score: 0
Joined: 12/18/2004
From:
Status: offline
|
Here is what I use as part of a logon script: Set wshNetwork = WScript.CreateObject("WScript.Network") UserName = UCASE(WSHNetwork.UserName) UserDomain = WSHNetwork.UserDomain ' Read the user's account "Member Of" tab info across the network ' once into a dictionary object. Set ObjGroupDict = CreateMemberOfObject(UserDomain, UserName) If MemberOf(ObjGroupDict, "HQ-Geographic Read") Then MapDrives "M", "\\co-data-02\GEOdata" End If If MemberOf(ObjGroupDict, "Admin Techs") or MemberOf(ObjGroupDict, "Domain Admins") or MemberOf(ObjGroupDict, "Help Desk SG") Then MapDrives "Z", "\\hq-adm-01\data" End If Function MemberOf(ObjDict, strKey) MemberOf = CBool(ObjGroupDict.Exists(strKey)) End Function Function CreateMemberOfObject(strDomain, UserName) Dim objUser, objGroup Set CreateMemberOfObject = CreateObject("Scripting.Dictionary") CreateMemberOfObject.CompareMode = vbTextCompare Set objUser = GetObject("WinNT://" & strDomain & "/" & UserName & ",user") For Each objGroup In objUser.Groups CreateMemberOfObject.Add objGroup.Name, "-" Next Set objUser = Nothing End Function Function MapDrives (driveLetter, dirPath) Dim wshNet Set wshNet = WScript.CreateObject("WScript.Network") ' This part checks to see if the drive letter is already mapped ' If so then it removes it, even if it is mapped persistant Set colDrives = wshNet.EnumNetworkDrives For i = 0 To colDrives.Count - 1 Step 2 If (colDrives(i) = ucase(driveLetter) & ":") Then wshNet.RemoveNetworkDrive ucase(driveLetter) & ":", true, true ' It seems to work better with a slight pause after the remove ' before it attempts to remap the drive letter. wscript.sleep(500) End If Next WSHNet.MapNetworkDrive ucase(driveLetter) & ":", dirPath end function Hope this helps.
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|