locked
Get the list of users from other domain RRS feed

  • Question

  • Hi All,
    
    I need to get the list of domain usrs. The users not necessorily be on the domain
    where I am logged in. (e.g. I am logged in on domain "Dom111" but I need the list of users from the domain "Dom222")
    
     I want this information on the basis of following - 
     1) Name of the Domain
     2) A valid User name (of-course with Admin rights for the Target domain) and password
    
    
    I am trying to use the following code - 
    
      DirectoryContext dc = new DirectoryContext(DirectoryContextType.Domain, "Dom222", "Administrator", "password");
      Domain domain = Domain.GetDomain(dc);
      DirectoryEntry de = domain.GetDirectoryEntry();
      
      FillList(de);
    
    Here is the FillList function
    
    private void FillList(DirectoryEntry de)
     {
      DirectorySearcher deSearch = new DirectorySearcher(de);
    
      deSearch.Filter = "(&(objectClass=user)(objectCategory=person))";
      SearchResultCollection results = deSearch.FindAll();
    
      //checkedListBox1.Items.Clear();
    
      foreach (SearchResult srUser in results)
      {
      DirectoryEntry deUser = srUser.GetDirectoryEntry();
      checkedListBox1.Items.Add(deUser.Properties["sAMAccountName"].Value.ToString());
      }
      checkedListBox1.Sorted = true;
    
     }
    
    This works fine for the domain where I logged in (i.e. Dom111) but for the other domain (Dom222), while executing the statement - Domain domain = Domain.GetDomain(dc);
    I am getting the error saying "The specified domain does not exist or cannot be contacted." 
    
    Now, For creating the dc if I use following - 
    DirectoryContext dcTemp = new DirectoryContext(DirectoryContextType.DirectoryServer, "Server_dom222", "administrator", "password");
    Then everything works fine. But as you can see I need to pass the "Domain Controller (Server) Name"which I want to avoid.
    
    Is it possible at all? If yes, How? 
    
    Thanks in Advance
    Sandy
    

    "An investment in knowledge pays the best interest." - Ben Franklin
    • Moved by SamAgain Tuesday, August 3, 2010 10:46 AM (From:.NET Base Class Library)
    Tuesday, August 3, 2010 9:22 AM

Answers

  • Hi,

      According to the description of that forum, "Questions about Active Directory and other directory stores, such as those accessible via LDAP". It's worth trying.


    Please mark the right answer at right time.
    Thanks,
    Sam
    • Marked as answer by sandy gadre Thursday, August 26, 2010 4:08 AM
    Wednesday, August 4, 2010 1:49 AM

All replies

  • Hi,

     Thanks for your post. Please consider Active Directory and LDAP forum as a better option.


    Please mark the right answer at right time.
    Thanks,
    Sam
    Tuesday, August 3, 2010 10:46 AM
  • Hi Sam,

    I am working not working on ASP. So is it okay to post it on the site you have suggested is fine?

    Thanks

    Sandy


    "An investment in knowledge pays the best interest." - Ben Franklin
    Wednesday, August 4, 2010 1:30 AM
  • Hi,

      According to the description of that forum, "Questions about Active Directory and other directory stores, such as those accessible via LDAP". It's worth trying.


    Please mark the right answer at right time.
    Thanks,
    Sam
    • Marked as answer by sandy gadre Thursday, August 26, 2010 4:08 AM
    Wednesday, August 4, 2010 1:49 AM