Answered by:
Get the list of users from other domain

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 10, 2010 10:03 AM not bcl question (From:.NET Base Class Library)
Tuesday, August 3, 2010 9:27 AM
Answers
-
Hi,
Thank you Johan for the helpful comments.
The problem was not with the syntax or anything, the problem was there in my network settings.
So now it is working.--Sandy
"An investment in knowledge pays the best interest." - Ben Franklin- Marked as answer by sandy gadre Tuesday, August 24, 2010 5:10 AM
Tuesday, August 24, 2010 5:09 AM
All replies
-
How about iterating through all the domain controllers that are returned by CurrentDomain.FindAllDomainControllers() or using the domain controller returned by CurrentDomain.FindDomainController(sitename) ?
Surely, the only way this will work is if there is a common domain controller.
Tuesday, August 3, 2010 9:52 AM -
Hi John,
Thanks for the quick reply. CurrentDomain.FindAllDomainControllers() is returning only one domain and its the same where I am logged in. although I can see other domains in Windows explorer "Entire Network-Microsoft Windows Network". What could be the problem?
Thanks
Sandy
"An investment in knowledge pays the best interest." - Ben FranklinWednesday, August 4, 2010 4:40 AM -
You are supposed to be able to navigate up the domain tree.
e.g.
CurrentDomain.FindAllDomainControllers()[0].Domain.FindAllDomainControllers()
But just in case you need more complete examples, find them here:
Wednesday, August 4, 2010 8:43 AM -
Hi,
Thank you Johan for the helpful comments.
The problem was not with the syntax or anything, the problem was there in my network settings.
So now it is working.--Sandy
"An investment in knowledge pays the best interest." - Ben Franklin- Marked as answer by sandy gadre Tuesday, August 24, 2010 5:10 AM
Tuesday, August 24, 2010 5:09 AM