Active Directory

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Does anyone have an example of how to list all of the users in active
directory?
Or better yet, list all of the users from the Global Address Book in
Exchange. I am building a custom Address Book and when you use the Outlook
to get the address book from custom program you get the annoying popup box,
so I though I could use the Active Directory to get the user list.

There is an example that lists users from AD on 'The Code Project' website,
but it only lists 1000 entries.


Thanks
Peter
 
Hi

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to enumerate all the domain
users using C#. If there is any misunderstanding, please feel free to let
me know.

I think this can be done using DirectoryService in .NET. Here I've found a
code snippet that can do this. the search results are in src collection.

DirectoryEntry de=new
DirectoryEntry("LDAP://s1-e2k/DC=FENGYUN,DC=GTEC","fengyun\\leolin"
,"1234");
string strGroupName = "Domain Users";
DirectorySearcher sh=new DirectorySearcher(de);
sh.Filter="(&(objectClass=user)(sAMAccountName="+strGroupName+"))";
sh.SearchScope=SearchScope.Subtree;

sh.PropertiesToLoad.Add("sAMAccountName");

SearchResultCollection src=sh.FindAll();
de.Close();
de.Dispose();
sh.Dispose();

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Peter,

Please make sure that you have had the correct domain, domain controller,
username and password when initializing the DirectoryEntry.

DirectoryEntry de=new
DirectoryEntry("LDAP://s1-e2k/DC=FENGYUN,DC=GTEC","fengyun\\leolin"
,"1234");

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
when I have
string strGroupName = "Domain Users";
I get src.Count = 0
but when I change "Domain Users" to an actual SamAccountName
I get src.Count = 1
 
Hi Peter,

Please try to replace

sh.Filter="(&(objectClass=user)(sAMAccountName="+strGroupName+"))";

with

sh.Filter="(&(objectClass=user))";

The DirectorySearcher class has a property named PageSize. You can try to
set PageSize to a value that is less than 1000 (for example 800) to do
paged search if you have more than 1000 users in the domain. It will return
all users.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top