LAN Web TCP Delphi

Title: Constructing an LDAP query to Get MS Exchange 2003 users list
Question: How to get exchange user list from active directory ?
Answer:
Active Directory allows you to perform directory wide searches by constructing an LDAP query. and in order to find only accounts having mailbox do the following :
First run Exchange System Manager and create an Address List then press the Filter Rules button then On the property page of the newly created address list you will find the LDAP query. like this (&(&(& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*))) ))))
you can use this to constructe your own query in delphi .net in this way :
uses
System.DirectoryServices,
System.Collections;
var
Entry: DirectoryEntry;
ds: DirectorySearcher;
sr: SearchResult;
begin
ListBox1.Items.Clear;
Entry := DirectoryEntry.Create('LDAP://mydomain.com');
ds := DirectorySearcher.Create(Entry);
ds.Filter := '(&(&(& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*))) ))))
';
{for..in... do is new in delphi 9 repeats a group of embedded statements for each element }
for sr in ds.FindAll() do
ListBox1.Items.Add
(
sr.GetDirectoryEntry().Path
+ '=' + sr.GetDirectoryEntry().Username
+ '=' + sr.GetDirectoryEntry().Name
);
Label2.Text := 'Total :' + IntToStr(listBox1.Items.Count);
end;
Thank you.