.net 如何列出所有的域帐户呢?在线急~~~~~~~~
如题....
------解决方案--------------------using System;
using System.DirectoryServices;
namespace ActiveDirectorySearch1
{
class Class1
{
static void Main (string[] args)
{
//Note : microsoft is the name of my domain for testing purposes.
DirectoryEntry entry = new DirectoryEntry(LDAP://microsoft);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ( "(objectClass=user) ");
Console.WriteLine( "Listing of computers in the Active Directory ");
Console.WriteLine( "================ "); foreach(SearchResult resEnt in mySearcher.FindAll())
{
Console.WriteLine(resEnt.GetDirectoryEntry().Name.ToString()); }
Console.WriteLine( "==== End of Listing ===== ");
}
}
}
------解决方案--------------------DirectoryEntry root = new DirectoryEntry( "WinNT: ");
DirectoryEntries domains = root.Children;
domains.SchemaFilter.Add( "domain ");
foreach (DirectoryEntry domain in domains)
{
DirectoryEntries computers = domain.Children;
computers.SchemaFilter.Add( "computer ");
foreach (DirectoryEntry computer in computers)
{
DirectoryEntries users = computer.Children;
users.SchemaFilter.Add( "user ");
foreach (DirectoryEntry user in users)
{
//用户名user.name;
}
}
}