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()