.Net Runtime Library for Delphi
CNClrLib.DirectoryServices Namespace

The CNClrLib.DirectoryServices namespace provides easy access to Active Directory Domain Services. The namespace contains two component interfaces, DirectoryEntry and DirectorySearcher , which use the Active Directory Services Interfaces (ADSI) technology. ADSI is the set of interfaces that Microsoft provides as a flexible tool for working with a variety of network providers. ADSI gives the administrator the ability to locate and manage resources on a network with relative ease, regardless of the size of the network. The namespace interfaces are defined as Classes and interfaces in C# System.DirectoryServices namespaces.


The example below uses DirectoryEntry interface.

program DirectoryServicesExample; {$APPTYPE CONSOLE} {$R *.res} uses SysUtils, CNClrLib.DirectoryServices, CNClrLib.Core; var Console: _Console; entry: _DirectoryEntry; mySearcher: _DirectorySearcher; objCollection: OleVariant; searchResult: _SearchResultCollection; keyEnumerator: _IEnumerator; key: string; I, J: Integer; begin try Console := CoConsole.CreateInstance; entry := CoDirectoryEntry.CreateInstance('LDAP://MCBcorp, DC=com'); Console.WriteLine_14('Name = ' + entry.Name); Console.WriteLine_14('Path = ' + entry.Path); Console.WriteLine_14('SchemaClassName = ' + entry.SchemaClassName); Console.WriteLine_14('Properties:'); Console.WriteLine_14('====================================='); keyEnumerator := entry.Properties.PropertyNames.AsIEnumerable.GetEnumerator; while keyEnumerator.MoveNext do begin key := keyEnumerator.Current; Console.WriteLine_14(Chr(9) + key + ' = '); for J := 0 to entry.Properties[key].Count - 1 do begin objCollection := entry.Properties[key][J]; Console.WriteLine_15(#13#10 + #13#10 + '{0}', objCollection); end; Console.WriteLine_14('==================================='); end; mySearcher := CoDirectorySearcher.CreateInstance(entry); mySearcher.Filter := '(objectClass=*)'; Console.WriteLine_14('Active Directory Information'); Console.WriteLine_14('====================================='); searchResult := mySearcher.FindAll; for I := 0 to searchResult.Count - 1 do begin Console.WriteLine_14(searchResult[I].GetDirectoryEntry.Name); Console.WriteLine_14(searchResult[I].GetDirectoryEntry.Path); Console.WriteLine_14(searchResult[I].GetDirectoryEntry.NativeGuid); Console.WriteLine_14('==================================='); end; except on E: Exception do begin Console.WriteLine_14(E.message); end; end; end.