2009-09-17 61 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(); 

     } 
    }