¤ For the moment i can read through a hierachie of the AD by browsing bye the
¤ use of LDAP:// strings
¤
¤ Now i can get to the level of finding the string of a user
¤ LDAP://CN=BlendemanDirk,OU=Users,OU=Antwerp,OU=BE,OU=SE,DC=be,DC=domain,DC=w
¤ e
¤ but now the problems is, how do i find date about the users. I Would like to
¤ retrieve his emailaddress and the groups his in.
¤
¤ Does anyone know a way?
¤
¤ or a simple way to find a user in the active directory, or to find a group
¤ and retrieving it's users...
¤
The following code should help:
Public Function GetUserInfo(ByVal UserID As String)
Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)
If UserID = "" Then
UserID = System.Security.Principal.WindowsIdentity.GetCurrent.Name.Split("\"c)(1)
End If
Dim ADSearchResult As System.DirectoryServices.SearchResult
ADSearch.PropertiesToLoad.Add("memberOf")
ADSearch.Filter = ("(samAccountName=" & UserID & ")")
ADSearch.SearchScope = SearchScope.Subtree
Dim UserFound As SearchResult = ADSearch.FindOne()
Dim propertyCount As Integer = UserFound.Properties("memberOf").Count
If Not IsNothing(UserFound) Then
Console.WriteLine(UserFound.GetDirectoryEntry().Properties.Item("mail").Value)
Dim propertyCounter As Integer
Dim dn As String
For propertyCounter = 0 To propertyCount - 1
dn = CType(UserFound.Properties("memberOf")(propertyCounter), String)
Console.WriteLine(dn.ToString)
Next
End If
End Function
Paul
~~~~
Microsoft MVP (Visual Basic)