2016-05-17 29 views
0

我一直在使用此功能从他们的用户名(我的所有用户都在同一个域中)找到用户的电子邮件地址没有问题,但现在一些用户有已经升级到Windows 10,我得到一个错误:LDAP服务器不可操作错误在Windows 10上发生只有

The server is not operational

我已经修改了我的代码参照这个问题,答案,所以现在我拿起​​默认命名上下文,但错误依然存在: 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的地方。

有什么建议吗?

+0

此代码是否在每个用户的计算机上运行? –

+0

是的,它在Windows 7和8中可以正常工作,但在Windows 10中出错。它将电子邮件发送给其他用户,该用户名已保存在数据库中。 – DovesandChicks

+0

这些Windows 10计算机是否与Windows 7/8相同? –

回答

0

我不知道它为什么会崩溃在LDAP:// RootDSE。但是,如果您只有一个域名,则可以使用强名称代替域名,而不是使用RootDSE。

您可以使用域名DNS名称:

Dim entry As New DirectoryServices.DirectoryEntry("LDAP://domain.com") 

或域名专有名称:

Dim entry As New DirectoryServices.DirectoryEntry("LDAP://DC=domain,DC=com") 

看看是否有什么差别。

相关问题