【发布时间】:2016-05-17 11:35:18
【问题描述】:
我一直在使用此功能从用户名中查找用户电子邮件地址(我的所有用户都在同一个域中)没有问题,但现在一些用户已升级到 Windows 10,我收到错误消息:
服务器无法运行
我已经参考这个问题和答案对我的代码进行了更改,所以现在我选择了默认命名上下文,但错误仍然存在: System.DirectoryServices - The server is not operational
Public Function UserEmail(ByRef Username As String) As String
UserEmail = ""
Dim deRoot As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
If Not deRoot Is DBNull.Value Then
Dim defaultNamingContext As String = deRoot.Properties("defaultNamingContext").Value.ToString()
Dim path As String
path = "LDAP://" & defaultNamingContext
Dim entry As New DirectoryServices.DirectoryEntry(Path)
Dim search As New DirectoryServices.DirectorySearcher(entry)
search.Filter = "(&(objectClass=user)(anr=" + Username + "))"
search.PropertiesToLoad.Add("mail")
Dim result As DirectoryServices.SearchResult
result = search.FindOne
If IsDBNull(result) Then
UserEmail = ""
Else
UserEmail = result.Properties("mail")(0)
End If
End If
Return UserEmail
End Function
代码在我的用户使用 Windows 7 和 8 时运行良好。
有什么建议吗?
【问题讨论】:
-
这段代码是否在每个用户的机器上运行?
-
是的,它在 Windows 7 和 8 中运行良好,但在 Windows 10 中出错。它将电子邮件发送给另一个用户,该用户名已保存在数据库中。
-
这些 Windows 10 机器是否与 Windows 7/8 机器加入了同一个域?
-
哪一行抛出异常?
-
它们都在同一个域中,并且行 dim deRoot as New DirectoryServices 抛出异常。
标签: vb.net active-directory ldap