我正在尝试获取完整的用户列表及其电子邮件地址。在尝试了很多事情之后,下面终于给了我某种形式的快乐但是我得到了这个错误这个错误:
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()