【发布时间】:2019-06-06 13:44:53
【问题描述】:
在我的应用程序中,我有一个“受众选择器”,可让您在 Active Directory 中搜索组和用户。群组位很有效,但我遇到了用户位的问题。
这是我的代码:
Public Function GetGroups() As List(Of String)
Dim objADAM As DirectoryEntry ' Binding object.
Dim objGroupEntry As DirectoryEntry ' Group Results.
Dim objSearchADAM As DirectorySearcher ' Search object.
Dim objSearchResults As SearchResultCollection ' Results collection.
Dim strPath As String ' Binding path.
Dim result As New List(Of String)
strPath = "LDAP://MYDOMAINCONTROLLER.MYDOMAIN"
objADAM = New DirectoryEntry(strPath)
objADAM.RefreshCache()
Try
objSearchADAM = New DirectorySearcher(objADAM)
objSearchADAM.Filter = "(&(objectClass=" & AudienceSelector.searchtype.Text & ")(cn=" & AudienceSelector.TextBox1.Text & "))"
objSearchADAM.SearchScope = SearchScope.Subtree
If AudienceSelector.searchtype.Text = "user" Then
objSearchADAM.PropertiesToLoad.Add("SAMAccountName")
End If
objSearchResults = objSearchADAM.FindAll()
Catch e As Exception
End Try
Try
If objSearchResults.Count <> 0 Then
Dim objResult As SearchResult
For Each objResult In objSearchResults
objGroupEntry = objResult.GetDirectoryEntry
result.Add(objGroupEntry.Name)
Next objResult
End If
Catch e As Exception
End Try
Return result
End Function
因此,如果 AudienceSelector.searchtype = user,则返回用户列表,但我得到了友好名称,并且我需要 SAMAccountName。 因此,我将返回 'John Smith' 而不是 'john.smith'。
我四处搜索并尝试添加 PropertiesToLoad 位以引入 SAMAcountName,但它每次都给我一个友好的名称。
谁能看出我哪里出错了?
在此先感谢您的帮助:-D
【问题讨论】:
标签: active-directory visual-studio-2017 user-profile