scream Posted March 1, 2011 Posted March 1, 2011 Hi, i have created below logon script to mount network drive based on user name: set objShell = CreateObject("Wscript.Shell") strUserName = objShell.ExpandEnvironmentStrings("%username%") Set objWSHNet = CreateObject("WScript.Network") 'Map drive for Username objWSHNet.MapNetworkDrive "X:", "\\servername\" & strUsername & "$" if err.number=0 then sDrive = "X:\" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(sDrive).Self.Name = "Home Folder" end if now i want to map folders based on the user's group memberships. please help me in this regards. Quote
mmthomas Posted April 1, 2011 Posted April 1, 2011 Here is a sample from another site on mapping based on group memberships: ' GroupMap.vbs ' VBScript to test group membership ' Script can be amended to actually MapNetworkDrive ' Author Guy Thomas http://computerperformance.co.uk/ ' Version 3.3 - May 2010 ' ----------------------------------------------------' Option Explicit Dim objNetwork, objUser, CurrentUser Dim strGroup ' Initialise Groups with Const Const Dentists_Group = "cn=dentists" Const Managers_Group = "cn=managers" Const What_ever_you_Like = "cn=any_lower_case_group" Const Users_Group = "cn=users" Const Administrators_Group = "cn=administrators" ' Create objects and extract strGroup values Set objNetwork = CreateObject("WScript.Network") Set objUser = CreateObject("ADSystemInfo") Set CurrentUser = GetObject("LDAP://" & objUser.UserName) strGroup = LCase(Join(CurrentUser.MemberOf)) ' If logic testing strGroup for the values in Const groups If InStr(strGroup, lcase(Dentists_Group)) Then WScript.Echo "Dentists " ' objNetwork.MapNetworkDrive "h:", "\\Server\Users\" _ ' & objNetwork.UserName ' For a production script remove the WScript ' Activate mapnetworkdrive by removing the apostrophes (' Rem) ElseIf InStr(strGroup, lcase(Managers_Group)) Then WScript.Echo " Manager " ' objNetwork.MapNetworkDrive "h:", "\\YourServer\Users\"_ ' & objNetwork.UserName ElseIf InStr(strGroup, lcase(Administrators_Group)) Then WScript.Echo "Administrator: " & strGroup ' objNetwork.MapNetworkDrive "h:", "\\Another Server\Users\" _ ' & objNetwork.UserName ElseIf InStr(strGroup, lcase(Users_Group)) Then WScript.Echo " Only a User... " ' objNetwork.MapNetworkDrive "y:", "\\alan\home\" _ ' & objNetwork.UserName End If Wscript.Echo "Finished Testing for Groups " WScript.Quit ' End of example VBScript . Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.