How to get list of computer names in a domain using C# ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
using System.DirectoryServices;
public void PrintComputersInDomain (string domainName)
{
DirectoryEntry de = new DirectoryEntry ("LDAP://" + domainName);
de.Children.SchemaFilter.Add ("computer");
foreach (DirectoryEntry c in de.Children)
{
Console.WriteLine (c.Name);
}
}
from http://msmvps.com/blogs/siva/archive/2008/01/25/enumerating-computers-in-a-domain.aspx
回答2:
If you are on a windows domain, you can run an LDAP query against the directory to pull back a list of Machine Accounts