1
我正在嘗試獲取用戶的完整列表及其電子郵件地址。在嘗試了很多事情之後,下面終於給了我某種形式的喜悅,但是我得到這個錯誤此錯誤:DirectoryServices搜索超出範圍錯誤
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
有誰知道爲什麼發生這種情況以及如何防止這種情況? 完整的代碼如下。
Dim entry As DirectoryEntry = Nothing
Dim search As DirectorySearcher = Nothing
entry = New DirectoryEntry()
search = New DirectorySearcher()
search.Filter = "(&(objectCategory=person)(objectClass=user)(mail=*@companyname.com*))"
search.Sort.PropertyName = "cn"
Dim result As SearchResultCollection = search.FindAll()
For Each res As SearchResult In result
Dim Name = res.Properties("cn")(0).ToString()
Dim Email = res.Properties("mail")(0).ToString()
WindowsForm1.ListBox1.Items.Add(Name & " <" & Email & ">")
Next
entry.Dispose()
search.Dispose()
result.Dispose()