G
Guest
I am having a hard time trying to communicate to the Active Directories to
retrieve the following:
User Name
Email Address
Phone
Groups User is assigned to
The last one is the most important. I am trying to develop this in VB.NET.
Code Follows. Please give code examples if possible.
Thanks,
Imports System.DirectoryServices
Dim m_obDirEntry As New DirectoryEntry("LDAP://[DOMAIN]/", )
Dim search As DirectorySearcher = New DirectorySearcher(m_obDirEntry)
search.Filter = "(cn=" & [username] & ")"
search.PropertiesToLoad.Add("memberOf")
Dim groupNames As StringBuilder = New StringBuilder
Dim result As SearchResult = search.FindOne()
Dim propertyCount As Integer = result.Properties("memberOf").Count
Dim dn As String
Dim equalsIndex, commaIndex
Dim propertyCounter As Integer
For propertyCounter = 0 To propertyCount - 1
dn = CType(result.Properties("memberOf")(propertyCounter),
String)
equalsIndex = dn.IndexOf("=", 1)
commaIndex = dn.IndexOf(",", 1)
If (equalsIndex = -1) Then
End If
groupNames.Append(dn.Substring((equalsIndex + 1),
(commaIndex - equalsIndex) - 1))
groupNames.Append("|")
Next
TextBox1.Text = groupNames.ToString
retrieve the following:
User Name
Email Address
Phone
Groups User is assigned to
The last one is the most important. I am trying to develop this in VB.NET.
Code Follows. Please give code examples if possible.
Thanks,
Imports System.DirectoryServices
Dim m_obDirEntry As New DirectoryEntry("LDAP://[DOMAIN]/", )
Dim search As DirectorySearcher = New DirectorySearcher(m_obDirEntry)
search.Filter = "(cn=" & [username] & ")"
search.PropertiesToLoad.Add("memberOf")
Dim groupNames As StringBuilder = New StringBuilder
Dim result As SearchResult = search.FindOne()
Dim propertyCount As Integer = result.Properties("memberOf").Count
Dim dn As String
Dim equalsIndex, commaIndex
Dim propertyCounter As Integer
For propertyCounter = 0 To propertyCount - 1
dn = CType(result.Properties("memberOf")(propertyCounter),
String)
equalsIndex = dn.IndexOf("=", 1)
commaIndex = dn.IndexOf(",", 1)
If (equalsIndex = -1) Then
End If
groupNames.Append(dn.Substring((equalsIndex + 1),
(commaIndex - equalsIndex) - 1))
groupNames.Append("|")
Next
TextBox1.Text = groupNames.ToString