G
Guest
Hello all,
I am trying to get all 'active' user details (username, firstname,
lastname) from win 2003 AD server using System.DirectoryServices. It works
fine. But it is too slow for getting all the 400 users. The following is the
code i have written.
I found that its doing s pretty quick search. But its taking quite some time
inside the 'foreach' loop to get the DirectoryEntry for each searchresult.
Any suggestions welcome! Thanks in advance.
public void GetAvailableUsers()
{
DirectorySearcher dSearcher = new DirectorySearcher("LDAP://DC=" +
ADServers[0].Code.Trim() + ",DC=" + this.domain + ",DC=ORG");
dSearcher.SearchScope = SearchScope.Subtree;
dSearcher.Filter =
"(&(objectCategory=person)(objectClass=user))";
dSearcher.PropertiesToLoad.Add("givenName");
dSearcher.PropertiesToLoad.Add("sn");
dSearcher.PropertiesToLoad.Add("sAMAccountName");
dSearcher.PropertiesToLoad.Add("userAccountControl");
SearchResultCollection sResults = dSearcher.FindAll();
try
{
int i = 0;
foreach (SearchResult sResult in
sResults)//dSearcher.FindAll())
{
DirectoryEntry dirEntry = sResult.GetDirectoryEntry();
i += 1;
if
(((((int)dirEntry.Properties["userAccountControl"].Value) & 2) == 0) &&
!(this.peakNetUsers.Contains(domain + @"\" +
dirEntry.Properties["sAMAccountName"].Value.ToString()))) //0=ENABLED
2=DISABLED
{
//add user tomy list
}
}
}
catch (Exception ex)
{
//MessageBox.Show("Critical AD Server Error : " +
ex.Message, "Critical Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
I am trying to get all 'active' user details (username, firstname,
lastname) from win 2003 AD server using System.DirectoryServices. It works
fine. But it is too slow for getting all the 400 users. The following is the
code i have written.
I found that its doing s pretty quick search. But its taking quite some time
inside the 'foreach' loop to get the DirectoryEntry for each searchresult.
Any suggestions welcome! Thanks in advance.
public void GetAvailableUsers()
{
DirectorySearcher dSearcher = new DirectorySearcher("LDAP://DC=" +
ADServers[0].Code.Trim() + ",DC=" + this.domain + ",DC=ORG");
dSearcher.SearchScope = SearchScope.Subtree;
dSearcher.Filter =
"(&(objectCategory=person)(objectClass=user))";
dSearcher.PropertiesToLoad.Add("givenName");
dSearcher.PropertiesToLoad.Add("sn");
dSearcher.PropertiesToLoad.Add("sAMAccountName");
dSearcher.PropertiesToLoad.Add("userAccountControl");
SearchResultCollection sResults = dSearcher.FindAll();
try
{
int i = 0;
foreach (SearchResult sResult in
sResults)//dSearcher.FindAll())
{
DirectoryEntry dirEntry = sResult.GetDirectoryEntry();
i += 1;
if
(((((int)dirEntry.Properties["userAccountControl"].Value) & 2) == 0) &&
!(this.peakNetUsers.Contains(domain + @"\" +
dirEntry.Properties["sAMAccountName"].Value.ToString()))) //0=ENABLED
2=DISABLED
{
//add user tomy list
}
}
}
catch (Exception ex)
{
//MessageBox.Show("Critical AD Server Error : " +
ex.Message, "Critical Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}