473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

USERS IN NESTED GROUPS

Hi!

I have the function below that return all users in a group, but this code
does not work if there are nested groups.

Can anyone tell me what to change to also get the users in the nested
groups?
Sub GetGroupMembers(ByVal ggmGroup As String, ByRef ggmMembers As
System.Collections.Generic.List(Of String))
Try
Dim entry As DirectoryEntry = New DirectoryEntry(ggmGroup)
Dim searcher As DirectorySearcher = New DirectorySearcher(entry)
searcher.Filter = "(objectClass=*)"
Dim rangeStep As System.UInt32 = 1000
Dim rangeLow As System.UInt32 = 0
Dim rangeHigh As System.UInt32 = CUInt(rangeLow + (rangeStep -
1))
Dim lastQuery As Boolean = False
Dim quitLoop As Boolean = False

Do
Dim attributeWithRange As String
If Not lastQuery Then
attributeWithRange =
String.Format("member;range={0}-{1}", rangeLow, rangeHigh)
Else
attributeWithRange = String.Format("member;range={0}-*",
rangeLow)
quitLoop = True
End If
searcher.PropertiesToLoad.Clear()
searcher.PropertiesToLoad.Add(attributeWithRange)
Dim results As SearchResult = searcher.FindOne

If results.Properties.Contains(attributeWithRange) Then
For Each obj As Object In
results.Properties(attributeWithRange)
ggmMembers.Add(obj.ToString)
Next
Else
lastQuery = True
End If
If Not lastQuery Then
rangeLow = CUInt(rangeHigh + 1)
rangeHigh = CUInt(rangeLow + (rangeStep - 1))
End If
Loop While Not quitLoop
Catch ex As Exception
Console.WriteLine("Error! Could not connect to group " &
ggmGroup & ". - " & ex.ToString)
End Try
End Sub
Regards

Morten Fagermoen

Oct 19 '06 #1
1 3321
Hi, again!

I made it work myself. So to you other newbies out there, here is the code:

Public Sub GetGroupMembers(ByVal ggmGroup As String, ByRef ggmMembers As
System.Collections.Generic.List(Of String))

Try
Dim entry As DirectoryEntry = New DirectoryEntry(ggmGroup)
Dim searcher As DirectorySearcher = New DirectorySearcher(entry)
searcher.Filter = "(objectClass=*)"
Dim rangeStep As System.UInt32 = 1000
Dim rangeLow As System.UInt32 = 0
Dim rangeHigh As System.UInt32 = CUInt(rangeLow + (rangeStep -
1))
Dim lastQuery As Boolean = False
Dim quitLoop As Boolean = False
Do
Dim attributeWithRange As String
If Not lastQuery Then
attributeWithRange =
String.Format("member;range={0}-{1}", rangeLow, rangeHigh)
Else
attributeWithRange = String.Format("member;range={0}-*",
rangeLow)
quitLoop = True
End If
searcher.PropertiesToLoad.Clear()
searcher.PropertiesToLoad.Add(attributeWithRange)
Dim results As SearchResult = searcher.FindOne

If results.Properties.Contains(attributeWithRange) Then
For Each obj As Object In
results.Properties(attributeWithRange)
Dim curObject As New DirectoryEntry("LDAP://" +
obj.ToString)
If
UCase(Split(Split(curObject.Properties("objectCate gory")(0).ToString,
",")(0), "=")(1)) = "GROUP" Then
GetGroupMembers("LDAP://" &
DSName(curObject.Properties("samAccountName")(0).T oString), ggmMembers)
End If
ggmMembers.Add(obj.ToString)
Next
Else
lastQuery = True
End If
If Not lastQuery Then
rangeLow = CUInt(rangeHigh + 1)
rangeHigh = CUInt(rangeLow + (rangeStep - 1))
End If
attributeWithRange = Nothing
results = Nothing
Loop While Not quitLoop

entry = Nothing
searcher = Nothing
rangeStep = Nothing
rangeLow = Nothing
rangeHigh = Nothing
lastQuery = Nothing
quitLoop = Nothing

Catch ex As Exception
Console.WriteLine("Error! Could not connect to group " &
ggmGroup & ". - " & ex.ToString)
End Try
End Sub


************************************************** ************************************************** **************************
"Morten Fagermoen" <mo****@fagermoen.comwrote in message
news:uM**************@TK2MSFTNGP04.phx.gbl...
Hi!

I have the function below that return all users in a group, but this code
does not work if there are nested groups.

Can anyone tell me what to change to also get the users in the nested
groups?
Sub GetGroupMembers(ByVal ggmGroup As String, ByRef ggmMembers As
System.Collections.Generic.List(Of String))
Try
Dim entry As DirectoryEntry = New DirectoryEntry(ggmGroup)
Dim searcher As DirectorySearcher = New
DirectorySearcher(entry)
searcher.Filter = "(objectClass=*)"
Dim rangeStep As System.UInt32 = 1000
Dim rangeLow As System.UInt32 = 0
Dim rangeHigh As System.UInt32 = CUInt(rangeLow + (rangeStep -
1))
Dim lastQuery As Boolean = False
Dim quitLoop As Boolean = False

Do
Dim attributeWithRange As String
If Not lastQuery Then
attributeWithRange =
String.Format("member;range={0}-{1}", rangeLow, rangeHigh)
Else
attributeWithRange =
String.Format("member;range={0}-*", rangeLow)
quitLoop = True
End If
searcher.PropertiesToLoad.Clear()
searcher.PropertiesToLoad.Add(attributeWithRange)
Dim results As SearchResult = searcher.FindOne

If results.Properties.Contains(attributeWithRange) Then
For Each obj As Object In
results.Properties(attributeWithRange)
ggmMembers.Add(obj.ToString)
Next
Else
lastQuery = True
End If
If Not lastQuery Then
rangeLow = CUInt(rangeHigh + 1)
rangeHigh = CUInt(rangeLow + (rangeStep - 1))
End If
Loop While Not quitLoop
Catch ex As Exception
Console.WriteLine("Error! Could not connect to group " &
ggmGroup & ". - " & ex.ToString)
End Try
End Sub
Regards

Morten Fagermoen
Oct 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cat | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I'm getting a validation error when I try to restrict the content of nested groups with xs:redefine whereas the same restriction on xs:element's...
3
by: Mark | last post by:
Hi, can anyone please tell me (Given a group name) how I can retrieve just those users associated with that group using Active Directory using LDAP?? I am using the code below with not much luck...
1
by: le_sloth | last post by:
Hi I'm generating a series of reports from an application that will be published on a client's intranet. The idea is that each of these reports is arranged into major product groups,...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
10
by: Robert Rodriguez | last post by:
does anyone know if the ms c compiler has nested function support, I have a large gcc project I need to merge into another ms c program. Thanks in advance.
0
by: James | last post by:
Hello All, I am working in a Windows NT domain environment, working with C#. What I want to be able to do is view all the groups a user belongs to, and also be able to add the users to groups. ...
0
by: Andrew Warren | last post by:
I have a need for a non-recursive technique to determine whether a user is a member of a specified group or any of its nested sub-groups I have read some of the posts regarding enumerating members...
0
by: Petra Hübner | last post by:
Hello Newsgroup, does anybody has an example, how can I read all the groups, who the user is member of (including nested groups) An Example would be great. Thanks Petra
4
by: Allen | last post by:
For my web-based php regex find/replace do-hickey, I need to match individual back references and wrap a tag around them so they'll be unique to the rest of the match for individual color markup. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.