2016-05-17 28 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") 

看看是否有什麼差別。

相關問題