procedure TForm1.Button4Click(Sender: TObject);
var obj : IAds;
search : IDirectorySearch;
tst : PWideChar;
p :
array[0..0]
of PWideChar;
cls : IADsClass;
cont : IADsContainer;
i : integer;
ptrResult : THandle;
col : ads_search_column ;
hr : HResult;
opt :
array[0..0]
of ads_searchpref_info;
// has to be an array
dwErr : DWord;
szErr :
array[0..255]
of WideCHar;
szName :
array[0..255]
of WideChar;
begin
lbDsSearch.Items.CLear;
AdsGetObject(edtDSPath.Text, IDirectorySearch, search);
try
p[0] := StringToOleStr('
Name');
opt[0].dwSearchPref := ADS_SEARCHPREF_SEARCH_SCOPE;
opt[0].vValue.dwType := ADSTYPE_INTEGER;
opt[0].vValue.Integer := ADS_SCOPE_SUBTREE;
hr := search.SetSearchPreference(@opt[0],1);
if (hr <> 0)
then
begin
hr := ADsGetLastError(dwErr, @szErr[0], 254, @szName[0], 254);
ShowMessage(WideCharToString(szErr));
Exit;
end;
hr := search.ExecuteSearch('
(objectCategory=User)',@p[0], 1, ptrResult);
hr := search.GetNextRow(ptrResult);
while (hr <> S_ADS_NOMORE_ROWS)
do
begin
hr := search.GetColumn(ptrResult, p[0],col);
if Succeeded(hr)
then
begin
if col.pADsValues <>
nil then
lbDsSearch.Items.Add(col.pAdsvalues^.CaseIgnoreString);
search.FreeColumn(col);
end;
Hr := search.GetNextRow(ptrResult);
end;
finally
end;
end;