getting all users in a windows domain

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxsodapopxx5
    New Member
    • Dec 2006
    • 22

    getting all users in a windows domain

    Ok currently i am working in an environment with 20 computers all in the domain, which has about 40 users. These 40 users change often. I need to write an application that pulls all the usernames and if possible more information(i.e . There first and last name etc...) from the domain server. I am an administrator so i have full access to this server and can get to all the information manually through active directory on Windows Server 2003, but i found it redundant to have to type the information twice(i.e. once in active directory and again in the system i am tweaking). I have been researching the new classes for domains in the .net framework 2 and have come up blank any help would be great.

    ~xxsodapopxx5
  • xxsodapopxx5
    New Member
    • Dec 2006
    • 22

    #2
    I have started finding some things about this.


    i have found the code to get the current user on the domain.

    Code:
    my.User.Name
    i still need help on getting a collection of all of the users on the domain

    Comment

    • radcaesar
      Recognized Expert Contributor
      • Sep 2006
      • 759

      #3
      For this you have to query the active directory.

      The Assembly is System.Director y Services.

      Here Is for you,

      //namespace required
      using System.Director yServices;

      //creating an instance of DirectoryEntry pointing to the //“TestOU” with valid credentials.
      DirectoryEntry DE = new DirectoryEntry( @"LDAP://Norchio/OU=TestOU,DC=no rchio,DC=com"," Username","pass word",Authentic ationTypes.Serv erBind | AuthenticationT ypes.Secure);

      // creating an instance of DirectorySearch er which will search in AD.
      System.Director yServices.Direc torySearcher mySearcher = new System.Director yServices.Direc torySearcher(DE );

      //setting up the search filters like if we want users from OU in AD
      mySearcher.Filt er = ("(objectClass= user)");
      Console.WriteLi ne("Users Listing from Active Directory");

      foreach(System. DirectoryServic es.SearchResult resEnt in mySearcher.Find All())
      {
      ResultPropertyC ollection RCol = resEnt.Properti es;
      foreach(string myKey in RCol.PropertyNa mes)
      {
      string tab = " ";
      if (myKey == "samaccountname ")
      {
      Console.WriteLi ne(myKey + " ");
      foreach(object myCollection in RCol[myKey])
      {
      Console.WriteLi ne(tab + myCollection);
      }
      }
      }
      }
      Console.ReadLin e();

      Comment

      • xxsodapopxx5
        New Member
        • Dec 2006
        • 22

        #4
        I am very greatful for your help, this is much appreciated... although there is something that i am not understanding. I Primarily program in vb.net 2005 so this code is somewhat foreign. I can interpret most of the code but can you explaing this line?

        Code:
        //creating an instance of DirectoryEntry pointing to the //“TestOU” with valid credentials.
        DirectoryEntry DE = new DirectoryEntry(@"LDAP://Norchio/OU=TestOU,DC=norchio,DC=com","Username","password",AuthenticationTypes.ServerBind | AuthenticationTypes.Secure);
        i do not understand what the first 3 parameters after the @

        what path am i supposed to enter?

        Comment

        • xxsodapopxx5
          New Member
          • Dec 2006
          • 22

          #5
          bump. bump. bump.

          Comment

          Working...