type
ADS_SEARCH_HANDLE = THandle;
PADS_SEARCH_HANDLE = ^ADS_SEARCH_HANDLE;
// *********************************************************************//
// Interface: IDirectorySearch
// Flags: (0)
// GUID: {109BA8EC-92F0-11D0-A790-00C04FD8D5A8}
// *********************************************************************//
IDirectorySearch =
interface(IUnknown)
['
{109BA8EC-92F0-11D0-A790-00C04FD8D5A8}']
function SetSearchPreference(
var pSearchPrefs: ads_searchpref_info; dwNumPrefs: LongWord): HResult;
stdcall;
function ExecuteSearch(pszSearchFilter: PWideChar; pAttributeNames: PWideChar;
dwNumberAttributes: LongWord;
var phSearchResult: ADS_SEARCH_HANDLE): HResult;
stdcall;
function AbandonSearch(phSearchResult: ADS_SEARCH_HANDLE): HResult;
stdcall;
function GetFirstRow(hSearchResult: ADS_SEARCH_HANDLE): HResult;
stdcall;
function GetNextRow(hSearchResult: ADS_SEARCH_HANDLE): HResult;
stdcall;
function GetPreviousRow(hSearchResult: ADS_SEARCH_HANDLE): HResult;
stdcall;
function GetNextColumnName(hSearchHandle: ADS_SEARCH_HANDLE;
out ppszColumnName: PWideChar): HResult;
stdcall;
function GetColumn(hSearchResult: ADS_SEARCH_HANDLE; szColumnName: PWideChar;
out pSearchColumn: ads_search_column): HResult;
stdcall;
function FreeColumn(
var pSearchColumn: ads_search_column): HResult;
stdcall;
function CloseSearchHandle(hSearchResult: ADS_SEARCH_HANDLE): HResult;
stdcall;
end;
procedure TMainForm.Button1Click(Sender: TObject);
var
ColCount: DWORD;
ColNames:
array of PWideChar;
DirSearch: IDirectorySearch;
SearchHandle: ADS_SEARCH_HANDLE;
hr : HRESULT;
begin
ColCount := 1;
SetLength(ColNames, 3);
ColNames[0] := '
name';
ColNames[1] := '
description';
ColNames[2] := '
adspath';
hr := ADsGetObject(PWideChar('
LDAP://DC=rmi,DC=local'), IID_IDirectorySearch, Pointer(DirSearch));
if failed(hr)
then
Exit;
SearchHandle := 0;
hr := DirSearch.ExecuteSearch('
(objectClass=organizationalUnit)', @ColNames[0], Length(ColNames), SearchHandle);
if failed(hr)
then
Exit;
while DirSearch.GetNextRow(SearchHandle) <> S_ADS_NOMORE_ROWS
do
begin
// Do something with result
end;
DirSearch.CloseSearchHandle(SearchHandle);
DirSearch :=
nil;
end;