0
이 코드를 사용하여 AD에서 Windows 양식의 datagridview로 사용자를 검색합니다. 속성이 비어있는 한 제대로 작동합니다.VB.NET DirectorySearcher 빈 속성을 가진 AD 사용자를 검색하지 않습니다.
Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles Button9.Click
Dim dirEntry As System.DirectoryServices.DirectoryEntry
Dim mySearcher As System.DirectoryServices.DirectorySearcher
Dim domainName As String = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName
Try
dirEntry = New System.DirectoryServices.DirectoryEntry("LDAP://" & Environment.UserDomainName)
mySearcher = New System.DirectoryServices.DirectorySearcher(dirEntry)
mySearcher.Filter = "(samAccountName=" & TextBox8.Text & ")"
mySearcher.PropertiesToLoad.Add("samAccountName")
mySearcher.PropertiesToLoad.Add("DisplayName")
mySearcher.PropertiesToLoad.Add("Description")
mySearcher.PropertiesToLoad.Add("mail")
mySearcher.PropertiesToLoad.Add("ProfilePath")
mySearcher.PropertiesToLoad.Add("HomeDirectory")
mySearcher.PropertiesToLoad.Add("HomeDrive")
mySearcher.PropertiesToLoad.Add("GivenName")
mySearcher.PropertiesToLoad.Add("sn")
Dim sr As SearchResult = mySearcher.FindOne()
If sr Is Nothing Then 'return false if user isn't found
'MsgBox("cannot find")
End If
Dim de As System.DirectoryServices.DirectoryEntry = sr.GetDirectoryEntry()
Dim SAM As String = de.Properties("samAccountName").Item(0).ToString
If SAM = "" Then
SAM = " - "
End If
Dim DisplayName As String = de.Properties("DisplayName").Item(0).ToString
If DisplayName = "" Then
DisplayName = " - "
End If
Dim Description As String = de.Properties("Description").Item(0).ToString
If Description = "" Then
Description = " - "
End If
Dim Email As String = de.Properties("mail").Item(0).ToString
If Email = "" Then
Email = " - "
End If
Dim Profile As String = de.Properties("ProfilePath").Item(0).ToString
If Profile = "" Then
Profile = " - "
End If
Dim HomeDir As String = de.Properties("HomeDirectory").Item(0).ToString
If HomeDir = "" Then
HomeDir = " - "
End If
Dim HomeDrv As String = de.Properties("HomeDrive").Item(0).ToString
If HomeDrv = "" Then
HomeDrv = " - "
End If
Dim GivenName As String = de.Properties("GivenName").Item(0).ToString
If GivenName = "" Then
GivenName = " - "
End If
Dim Sn As String = de.Properties("sn").Item(0).ToString
If Sn = "" Then
Sn = " - "
End If
'DataGridView3.Rows.Add(de.Properties("samAccountName").Value.ToString, de.Properties("GivenName").Value.ToString & " " & de.Properties("sn").Value.ToString, de.Properties("ProfilePath").Value.ToString, de.Properties("HomeDirectory").Value.ToString, de.Properties("HomeDrive").Value.ToString, "", "", "", "", "")
DataGridView3.AllowUserToAddRows = True
DataGridView3.Rows.Add(SAM, DisplayName, Description, Email, Profile, "", HomeDir, "", HomeDrv, "")
DataGridView3.AllowUserToAddRows = False
Catch
End Try
dirEntry.Dispose()
mySearcher.Dispose()
End Sub
사용하는 코드의 부분 :
If SAM = "" Then
SAM = " - "
End If
이 있지만 나던 일을 방지하기위한 시도였다. AD에서 사용자를 찾고 빈 필드를 채우면 사용자가 검색됩니다.
원인을 식별하고 문제를 해결할 수있는 사람을 찾아 주시겠습니까?
내가 비주얼 스튜디오를 사용하고 내용
... 2010닷넷 3.5 +
많은 감사,
아론 내가 AD에 알다시피