
A logon script that maps drives according to the users group memberships
'~~Author~~. jerry Lees
'~~Script_Type~~.
VBScript '~~Sub_Type~~. LogonScripts
'~~Keywords~~. a logon script that maps drives according to the users group
memberships
'~~Comment~~.
'The script enumerates the groups in the domain and check to see that the
'user is or isn't a member of the group and maps drives accordingly.
'~~Script~~.
' written by jerry lees on 10/03/2000
' this is for 95/98 machines, they run login scripts before the user is
logged on so the username will always return NULL
' Note: there is a technet article on this topic... took me a while to find
it, (hope this helps someone)
Dim UserName
Username = ""
While UserName = ""
on error resume next
Set WSHNetwork = CreateObject("WScript.Network")
on error resume next
UserName = UCASE(WSHNetwork.UserName)
on error resume next
Set WSHNetwork = Nothing
WEnd
' end 95/98 wile/wend loop
' replace YOURDOMAIN with your domain name.
Set adsDomainGroups = GetObject("WinNT://YOURDOMAIN")
adsDomainGroups.Filter = Array("Group")
for each adsGroup in adsDomainGroups
Group = Ucase(adsgroup.name)
' add new groups and drives below here
If group = UCASE("Domain Admins") then CheckGroup adsgroup.name, Username,
"J:", "\\server1\sysadmin"
If group = UCASE("Admins") then CheckGroup adsgroup.name, Username, "J:",
"\\server3\sysadmin"
If group = UCASE("Producers") then CheckGroup adsgroup.name, Username,
"R:", "\\server2\ProjectDocs"
If group = UCASE("Sales") then CheckGroup adsgroup.name, Username, "S:",
"\\server3\Sales"
If group = UCASE("Administrative") then CheckGroup adsgroup.name, Username,
"M:", "\\server2\Administrative"
If group = UCASE("Accounting") then CheckGroup adsgroup.name, Username,
"Q:", "\\server3\accntng"
If group = UCASE("reports") then CheckGroup adsgroup.name, Username, "O:",
"\\Server4\reports"
If group = UCASE("doorway") then CheckGroup adsgroup.name,
Username,"W:","\\server5\doorway"
next
set adsuser = Nothing
set adsDomain = nothing
'the line below was here for testing purposes and debugging
'msgbox("DONE!")
sub CheckGroup(GroupName, username, Drive, unc)
'the line below was here for testing purposes and debugging
' MsgBox(groupname & " - " & username)
' replace YOURDOMAIN with your domain name.
Set AdsGroup = GetObject("WinNT://YOURDOMAIN/" & GroupName)
Set ADSGROUPMEMBERSHIP = AdsGroup.Members()
for each adsUser in adsgroupmembership
If UCase(adsUser.name) = username Then MapDrive Drive, UNC
next
End Sub
Sub mapdrive (driveletter, UNCString)
' MsgBox("Mapping Drive!")
Set WSHNetwork = WScript.CreateObject("WScript.Network")
On Error Resume Next
WSHNetwork.MapNetworkDrive driveletter, Uncstring
End sub
**** END SCRIPTS ****
I hope that this script can help anyone.