2009-09-17 50 views
0

如果我对全局编录做了一个查询(我打算使用SDS.P),那么应该如何选择起始路径,以便搜索整个GC?例如,我想枚举GC中的所有用户。 比方说,我的GC有用户3个域(一个家长,两个孩子):搜索全局编录

TEST.COM 
    ONE.TEST.COM 
    TWO.TEST.COM 

,我在ONE.TEST.COM的计算机上。我不想硬编码DC = XXX,DC = yyy,我想确定在运行时。

TIA! - 将会

回答

0

下面是一个例子功能查询全局编录:

class Program 
    { 

     static void Main() 
     { 

      DirectoryEntry entry = new DirectoryEntry("GC://dcserver.domain.local", 
                 "utility", 
                 "somepassword", 
                 AuthenticationTypes.Secure); 

      const string searchString = "(&(objectCategory=person)(objectClass=user))"; 

      DirectorySearcher searcher = new DirectorySearcher(entry, 
                   searchString, 
                   new string[] { "sAMAccountName", "cn" }); 

      SearchResultCollection resultCollection = searcher.FindAll(); 

      foreach (SearchResult result in resultCollection) 
      { 
       Console.WriteLine(result.Path + "\n" + 
            result.Properties["cn"][0] + "\n" + 
            result.Properties["samaccountname"][0] ); 
      } 

      Console.ReadLine(); 

     } 
    }