locked
What is DirectoryEntry's scope? (Active Directory) RRS feed

  • Question

  • User-1440297509 posted

    Hi,

    I'd like to get all the users from a domain using DirectoryServices.
    So much I learned that on the local computer I get the local AD users by the following way:

       DirectoryEntry de = new DirectoryEntry("WinNT://" + Environment.MachineName);
    
                foreach (DirectoryEntry item in de.Children)
    
                {
    
                    if (item.SchemaClassName == "User")
    
                       myList.Add(item.Name);                
    
                }
    
    



    If I liked to get the users from the domain (I assume the AD users are stored on an AD server), can the DirectoryEntry get its list just by defining its scope by this way?:

       DirectoryEntry de = new DirectoryEntry("WinNT://" + "ADserver");
    
                foreach (DirectoryEntry item in de.Children)
    
                {
    
                    if (item.SchemaClassName == "User")
    
                       myList.Add(item.Name);                
    
                }

    Or am I supposed to create the DirectoryEntry on the server that holds the AD users? What is the most effective way to get them?

    Thursday, August 6, 2009 5:57 PM

All replies