Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Map a drive for Domain Admins 1

Status
Not open for further replies.

zorex

IS-IT--Management
Aug 24, 2004
16
0
0
US
Hi everyone,

I'm running win2k w/ sp4.

I want to map a drive based on group. My admin user is in 'Domain Admins' group (which is in the 'Users' folder) and I want to map a drive that will be available only to that group.

I want it to check during the login if the user I'm using is a member of Domain Admins group and map S: drive if it is a member. How would I do that?

I tried the sample scripts from other threads but it won't work for me. I'm pretty new in vbscript. I would appreciate any help.

Please advise.

Thanks,
zorex
 
What have you done so far? What code have you tried? What specifically is the code you are using doing or not doing that is wrong?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Here ya go. We have a script that checks to see what groups a user is a member of, and then maps certain drives for that group of users. You can just modify it to meet your needs.

Option Explicit ' Force explicit declarations
'
' Variables
'
Dim WSHNetwork
Dim FSO
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs

Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
'
' Wait until the user is really logged in...
'
strUserName = ""
While strUserName = ""
WScript.Sleep 100 ' 1/10 th of a second
strUserName = WSHNetwork.UserName
Wend
strUserDomain = WSHNetwork.UserDomain

' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.

Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)
If MemberOf(ObjGroupDict, "GroupHere") Then
'wscript.echo "Is a member of "
'REM this line to Map Network Drives

'Map network Drives here, UNREM the below lines:
if not FSO.DriveExists("K:") then
WSHNetwork.MapNetworkDrive "k:", "mapdrivelocationhere"
Else
End If
Else
End If
If MemberOf(ObjGroupDict, "GroupHere") Then
'wscript.echo "Is a member of "
'REM this line to Map Network Drives
if not FSO.DriveExists("K:") then
WSHNetwork.MapNetworkDrive "k:", "mapdrivelocationhere"

'Map network Drives here, UNREM the below lines:
WSHNetwork.MapNetworkDrive "l:", "mapdrivelocationhere"
Else
End If
Else
End If
If MemberOf(ObjGroupDict, "GroupHere") Then
'wscript.echo "Is a member of ."
'REM this line to Map Network Drives

'Map network Drives here, UNREM the below lines:
WSHNetwork.MapNetworkDrive "k:", "mapdrivelocationhere"
Else
'wscript.echo "Is NOT a member of Domain Admins"
End If
If MemberOf(ObjGroupDict, "GroupHere") Then
'wscript.echo "Is a member of ."
'REM this line to Map Network Drives

'Map network Drives here, UNREM the below lines:
WSHNetwork.MapNetworkDrive "k:", "mapdrivelocationhere"

Else
'wscript.echo "Is NOT a member of Domain Admins"
End If
If MemberOf(ObjGroupDict, "GroupHere") Then
'wscript.echo "Is a member of "
'REM this line to Map Network Drives

'Map network Drives here, UNREM the below lines:
WSHNetwork.MapNetworkDrive "k:", "mapdrivelocationhere"
Else
'wscript.echo "Is NOT a member of Domain Admins"
End If
If MemberOf(ObjGroupDict, "GroupHere") Then
'wscript.echo "Is a member of "
'REM this line to Map Network Drives

'Map network Drives here, UNREM the below lines:
if not FSO.DriveExists("T:") then
WSHNetwork.MapNetworkDrive "T:", "mapdrivelocationhere"
Else
End If
Else
End If
if not FSO.DriveExists("Y:") then
WSHNetwork.MapNetworkDrive "y:", "mapdrivelocationhere"
Else
End If
Function MemberOf(ObjDict, strKey)
' Given a Dictionary object containing groups to which the user
' is a member of and a group name, then returns True if the group
' is in the Dictionary else return False.
'
' Inputs:
' strDict - Input, Name of a Dictionary object
' strKey - Input, Value being searched for in
' the Dictionary object
' Sample Usage:
'
' If MemberOf(ObjGroupDict, "DOMAIN ADMINS") Then
' wscript.echo "Is a member of Domain Admins."
' End If
'
'
MemberOf = CBool(ObjGroupDict.Exists(strKey))

End Function


Function CreateMemberOfObject(strDomain, strUserName)
' Given a domain name and username, returns a Dictionary
' object of groups to which the user is a member of.
'
' Inputs:
'
' strDomain - Input, NT Domain name
' strUserName - Input, NT username
'
Dim objUser, objGroup

Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
CreateMemberOfObject.CompareMode = vbTextCompare
Set objUser = GetObject("WinNT://" _
& strDomain & "/" _
& strUserName & ",user")
For Each objGroup In objUser.Groups
CreateMemberOfObject.Add objGroup.Name, "-"
Next
Set objUser = Nothing

End Function
 
Thank you both for your quick responses.

TomThumbKP, I will try what keybrdcowboy posted here first and I will let both of you know what the result is.

Thanks again.

Zorex
 
keybrdcowboy,

I'm getting this message when I run the script.

*******************************************
Script: logintest.vbs
Line: 117
Char: 2
Error: Out of stack space: 'MemberOf'
Code: 800A001C
Source: Microsoft VBScript runtime error
*******************************************

And this is what I have starting from Line 117, the 'MemberOf' function.

**********************************************************
Function MemberOf(ObjGroupDict, strKey)
If MemberOf(ObjGroupDict, "DOMAIN ADMINS") Then
wscript.echo "Is a member of Domain Admins."
End If
'
'
MemberOf = CBool(ObjGroupDict.Exists(strKey))
End Function
**********************************************************

Any idea?

Please advise.

Thanks,
zorex
 
You make an infinite recursive call to the MemberOf function inside the body of this function ...
I think you've discarded the comment marks

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you PHV.

I thought I needed that 'if' statement there.

Anyway, I tried putting back the comment marks on the 'if' statement and everything worked fine.

Thank you all, specially to you keybrdcowboy, for helping me out.

I would further test this script and will let you guys know the result. For the meantime, I will give keybrdcowboy a five star for a working script.

Thanks,
zorex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top