This documentation is archived and is not being maintained.

DirectorySearcher.SearchRoot Property

Gets or sets the node in the Active Directory hierarchy where the search starts.

[Visual Basic]
Public Property SearchRoot As DirectoryEntry
public DirectoryEntry SearchRoot {get; set;}
public: __property DirectoryEntry* get_SearchRoot();
public: __property void set_SearchRoot(DirectoryEntry*);
public function get SearchRoot() : DirectoryEntry;
public function set SearchRoot(DirectoryEntry);

Property Value

The DirectoryEntry in the Active Directory hierarchy where the search starts. The default is a null reference (Nothing in Visual Basic).


If SearchRoot is a null reference (Nothing in Visual Basic), the search root is set to the root of the domain that your server is currently using.

There are several ways to search in the global catalog:

  • Enumerate the global catalog, and pick the first child.
  • Specify the server name. Use DsGetDcName to find the global catalog.
  • Get the global catalog's RootDSE and ask for "rootNamingContext".
  • Use the global catalog like LDAP. For example, "GC://OU=..., DC=..., DC=...".

The following C# code shows how to enumerate the global catalog and pick the first child.

DirectoryEntry entry = new DirectoryEntry("GC:");
IEnumerator ie = entry.Children.GetEnumerator();
entry = (DirectoryEntry)ie.Current;
DirectorySearcher search = new DirectorySearcher(entry);


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

DirectorySearcher Class | DirectorySearcher Members | System.DirectoryServices Namespace | DirectoryEntry