Dim DomainName As String = System.Environment.UserDomainName
Dim AccountName As String = System.Environment.UserName.ToLower()
try
Dim entry As New System.DirectoryServices.DirectoryEntry("LDAP://" & domainName)
Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)
mySearcher.Filter = ("(objectClass=user)") 'user表示用户,group表示组
For Each resEnt As System.DirectoryServices.SearchResult In mySearcher.FindAll()
Dim fullName As String = resEnt.GetDirectoryEntry().Name.ToString()
If resEnt.GetDirectoryEntry().Properties("samaccountname").Value.ToString().ToLower() = AccountName Then
msgbox(fullName.Substring(3, fullName.Length-3))
End If
Next
catch ex As exception
msgbox("连接不上......自己做操作")
msgbox(ex.message)
End try