我写了一个帮助类来获取域中的所有计算机,但它有点慢。虽然返回了 128 个对象,但我仍然想加快速度。有任何想法吗?
public class DomainBrowser
{
private const string Computer = "computer";
public string Domain { get; private set; }
public DomainBrowser(string domain)
{
this.Domain = domain.ToLower();
}
/// <summary>
/// This method returns a list of the computer names available in the current domain.
/// </summary>
/// <returns></returns>
public List<string> GetComputers()
{
var winDirEntries = new DirectoryEntry("WinNT:");
var computers = (from DirectoryEntry domain in winDirEntries.Children
where domain.Name.ToLower() == this.Domain
from DirectoryEntry pc in domain.Children
where pc.SchemaClassName.ToLower().Contains(Computer)
select pc.Name).ToList();
return computers;
}
}