Logon Script issues with nested group memberships
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Logon Script issues with nested group memberships

 
Post new topic   Reply to topic    Windows Server Forum Index -> Programming
Author Message
Michael Wright
Guest





Posted: Tue Dec 21, 2004 3:49 am    Post subject: Logon Script issues with nested group memberships Reply with quote

I am trying to create a logon script that will check the group membership of
a user logging on, and depending on the groups that the user is a member of,
map network drives. Binding to Winnt:// was easy to learn, but it couldn't
find nested memberships. I am trying to bind to LDAP:// (and use an array at
the same time) but for some reason it doesn't look like it is even checking
my group membership and mapping all drives. The code is below - any ideas?
Thanks!

Option Explicit

Dim strSpaces
Dim dicSeenGroupMember
Dim strFileServer
Dim strPrintServer
Dim objMember
Dim WshNetwork

Set WshNetwork = WScript.CreateObject("Wscript.Network")
Set dicSeenGroupMember = CreateObject("Scripting.Dictionary")

strSpaces = " "

Private Const D_SHARE_NAME = 0
Private Const D_GROUP_NAME = 1
Private Const D_DRIVE_LETTER = 2
Private Const D_FILE_SERVER = 3

Private astrNetworkDriveList()

FillNetworkDrives
MapNetworkDrives

Sub FillNetworkDrives

ReDim astrNetworkDriveList(D_FILE_SERVER,1)

astrNetworkDriveList(D_SHARE_NAME, 0) = "Public"
astrNetworkDriveList(D_GROUP_NAME, 0) = "Share Public Read"
astrNetworkDriveList(D_DRIVE_LETTER, 0) = "Q:"
astrNetworkDriveList(D_FILE_SERVER, 0) = "puck"

astrNetworkDriveList(D_SHARE_NAME, 1) = "Networking"
astrNetworkDriveList(D_GROUP_NAME, 1) = "Share Networking Modify"
astrNetworkDriveList(D_DRIVE_LETTER, 1) = "S:"
astrNetworkDriveList(D_FILE_SERVER, 1) = "puck"

End Sub

Sub MapNetworkDrives

Dim strDriveLetter
Dim strGroupName
Dim strGroupDNTree
Dim strFileServer
Dim strShareName
Dim strSpaces
Dim StrGroupADsPath
Dim lngD_Index
Dim lngD_UBound
lngD_UBound = UBound(astrNetworkDriveList, 2)
For lngD_Index = 0 to lngD_UBound
strGroupDNTree = ",ou=Security Groups,ou=arrow,dc=afs,dc=root,dc=local"
strDriveLetter = astrNetworkDriveList(D_DRIVE_LETTER, lngD_Index)
strFileServer = astrNetworkDriveList(D_FILE_SERVER, lngD_Index)
strShareName = astrNetworkDriveList(D_SHARE_NAME, lngD_Index)
strGroupName = astrNetworkDriveList(D_GROUP_NAME, lngD_Index)
strGroupADsPath = "LDAP://cn=" & strGroupName & strGroupDNTree
MapDrive strGroupADsPath, strSpaces, dicSeenGroupMember,
strDriveLetter, strFileServer, strShareName

strGroupDNTree = "Nothing"
strDriveLetter = "Nothing"
strFileServer = "Nothing"
strShareName = "Nothing"
strGroupName = "Nothing"
strGroupADsPath = "Nothing"
Next

End Sub





'************************
'* *
'* Function MapDrive *
'* *
'************************

Function MapDrive ( strGroupADsPath, strSpaces, dicSeenGroupMember,
strDriveLetter, strFileServer, strShareName)
Dim objGroup
set objGroup = GetObject(strGroupADsPath)
for each objMember In objGroup.Members
WshNetwork.MapNetworkDrive strDriveLetter,"\\" & strFileServer & "\" &
strShareName
if objMember.Class = "group" then
if dicSeenGroupMember.Exists(objMember.ADsPath) then
else
dicSeenGroupMember.Add objMember.ADsPath, 1
end if
end if
next
End Function
Back to top
Al Dunbar [MS-MVP]
Guest





Posted: Tue Dec 21, 2004 9:18 am    Post subject: Re: Logon Script issues with nested group memberships Reply with quote

"Michael Wright" <Michael Wright@discussions.microsoft.com> wrote in message
news:F293ED8E-6F08-4F87-AA7A-8411BAD0BA7A@microsoft.com...
Quote:
I am trying to create a logon script that will check the group membership
of
a user logging on, and depending on the groups that the user is a member
of,
map network drives. Binding to Winnt:// was easy to learn, but it couldn't
find nested memberships. I am trying to bind to LDAP:// (and use an array
at
the same time) but for some reason it doesn't look like it is even
checking
my group membership and mapping all drives. The code is below - any ideas?

Seems a bit more complex than perhaps necessary. I'd suggest you have a look
at Richard Mueller's excellent web site, starting at this page:

http://www.rlmueller.net/freecode1.htm

/Al

Quote:
Thanks!

Option Explicit

Dim strSpaces
Dim dicSeenGroupMember
Dim strFileServer
Dim strPrintServer
Dim objMember
Dim WshNetwork

Set WshNetwork = WScript.CreateObject("Wscript.Network")
Set dicSeenGroupMember = CreateObject("Scripting.Dictionary")

strSpaces = " "

Private Const D_SHARE_NAME = 0
Private Const D_GROUP_NAME = 1
Private Const D_DRIVE_LETTER = 2
Private Const D_FILE_SERVER = 3

Private astrNetworkDriveList()

FillNetworkDrives
MapNetworkDrives

Sub FillNetworkDrives

ReDim astrNetworkDriveList(D_FILE_SERVER,1)

astrNetworkDriveList(D_SHARE_NAME, 0) = "Public"
astrNetworkDriveList(D_GROUP_NAME, 0) = "Share Public Read"
astrNetworkDriveList(D_DRIVE_LETTER, 0) = "Q:"
astrNetworkDriveList(D_FILE_SERVER, 0) = "puck"

astrNetworkDriveList(D_SHARE_NAME, 1) = "Networking"
astrNetworkDriveList(D_GROUP_NAME, 1) = "Share Networking Modify"
astrNetworkDriveList(D_DRIVE_LETTER, 1) = "S:"
astrNetworkDriveList(D_FILE_SERVER, 1) = "puck"

End Sub

Sub MapNetworkDrives

Dim strDriveLetter
Dim strGroupName
Dim strGroupDNTree
Dim strFileServer
Dim strShareName
Dim strSpaces
Dim StrGroupADsPath
Dim lngD_Index
Dim lngD_UBound
lngD_UBound = UBound(astrNetworkDriveList, 2)
For lngD_Index = 0 to lngD_UBound
strGroupDNTree = ",ou=Security
Groups,ou=arrow,dc=afs,dc=root,dc=local"
strDriveLetter = astrNetworkDriveList(D_DRIVE_LETTER, lngD_Index)
strFileServer = astrNetworkDriveList(D_FILE_SERVER, lngD_Index)
strShareName = astrNetworkDriveList(D_SHARE_NAME, lngD_Index)
strGroupName = astrNetworkDriveList(D_GROUP_NAME, lngD_Index)
strGroupADsPath = "LDAP://cn=" & strGroupName & strGroupDNTree
MapDrive strGroupADsPath, strSpaces, dicSeenGroupMember,
strDriveLetter, strFileServer, strShareName

strGroupDNTree = "Nothing"
strDriveLetter = "Nothing"
strFileServer = "Nothing"
strShareName = "Nothing"
strGroupName = "Nothing"
strGroupADsPath = "Nothing"
Next

End Sub





'************************
'* *
'* Function MapDrive *
'* *
'************************

Function MapDrive ( strGroupADsPath, strSpaces, dicSeenGroupMember,
strDriveLetter, strFileServer, strShareName)
Dim objGroup
set objGroup = GetObject(strGroupADsPath)
for each objMember In objGroup.Members
WshNetwork.MapNetworkDrive strDriveLetter,"\\" & strFileServer & "\"
&
strShareName
if objMember.Class = "group" then
if dicSeenGroupMember.Exists(objMember.ADsPath) then
else
dicSeenGroupMember.Add objMember.ADsPath, 1
end if
end if
next
End Function
Back to top
Eng
Guest





Posted: Tue Dec 21, 2004 3:13 pm    Post subject: RE: Logon Script issues with nested group memberships Reply with quote

With the code below you can retrive the info..

This is a copy&paste of the script I use to do the same.. the script do more
than this.. so I think that this could be enough but try to check if some
variable are missing or some errors happen..But it works.. also for nested
groups using ldap to retrive info..

Bye
Eng



'******************************************
'*** Begin VARIABLE USED BY LDAP QUery ****
dim RootDSE, oDomain
dim Con, RS
dim strUserCN, strADOQueryString
dim oUserID, strGroups, strGroup, strGrouplist, strGroupSave
dim oGroup, strGroupArray(100), strUserGroups
dim intGroupNum, intArrayNum,mapline,MyArray,grpfrcsv
'*****************************************
'*** BEGIN MAIN PROGRAM ***
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
strNTName = wshNetwork.userName
sCompName = WshNetwork.ComputerName
sDominio = wshNetwork.UserDomain
REtrgrpinfo(strNTName) '** Call Routine to retrieve information
'** about groups membership
'******************************************


'*****************************************
'*************************************************
'** ROUTINE GEt info about user objct and after **
'** retrieve information about membership **
'*************************************************
SUB REtrgrpinfo(strUserID)

Set RootDSE = GetObject("LDAP://RootDSE")

Set con = CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"
con.Open "ADs Provider"

strADOQueryString = "<LDAP://" & RootDSE.Get("DefaultNamingContext") & _
">;(&(objectCLass=organizationalPerson)(cn=" & strUserID & _
"));cn,adspath;subtree"

set RS = con.Execute(strADOQueryString)

if not RS.EOF then
strUserCN = RS.Fields(1)
End if

set oUserID = GetObject(strUserCN)
strUserGroups = oUserID.memberof

GetGroups(strUserGroups)
i= 0
for intArrayNum = 1 to intGroupNum
'** strGroupList = strGroupList & vbcrlf & strGroupArray(intArrayNum)
Grouplist(intArrayNum) = strGroupArray(intArrayNum)
i=i+1
next

set con = nothing
set rs = nothing

End Sub

Sub GetGroups (strGroups)
if isempty(strGroups) then exit sub
if isarray(strGroups) then
for each strGroup in strGroups
intGroupNum = intGroupNum + 1
strGroupSave = strGroup
strGroup = left(strGroup,instr(strGroup,",")-1)
strGroup = mid(strGroup,instr(strGroup,"=")+1)
strGroupArray(intGroupNum) = strGroup
set oGroup = GetObject("LDAP://" & strGroupSave)
if not isempty(oGroup.memberof) Then GetGroups(oGroup.memberof)
next
Else
intGroupNum = intGroupNum + 1
strGroups = left(strGroups,instr(strGroups,",")-1)
strGroups = mid(strGroups,instr(strGroups,"=")+1)
strGroupArray(intGroupNum) = strGroups
End if

End Sub
'** Finished ROUTINE to retrieve info about groups memberships
'************************************************************
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Programming All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB