One user of the Delphi-PRAXiS asked, how to retrieve a list of either users or computers with the creation date, name and parents name. Since I had those information available, I just thought I post it here as well. Once again, you simple have to query the active directory using ADO. For the parent however, you need to get the object and then query its Parent property.
procedure TYourForm.btnSearchClick(Sender: TObject); var Conn: _Connection; Cmd: _Command; RS: _Recordset; Affected: OleVariant; Line: string; Obj: IADsUser; procedure RunQuery(Query: string); begin Cmd.CommandText := Query; // run query and return domain list RS := Cmd.Execute(Affected, EmptyParam, 0); if RS.EOF then Exit; RS.MoveFirst; while not RS.EOF do begin try Obj := VBGetObject(RS.Fields.Item[1].Value) as IADsUser; Line := Format('%s, %s, %s, %s', [RS.Fields.Item[0].Value, RS.Fields.Item[1].Value, RS.Fields.Item[2].Value, Obj.Parent]); mmoReport.Lines.Add(Line); except end; RS.MoveNext; end; end; begin mmoReport.Clear; // create objects Conn := CoConnection.Create; Cmd := CoCommand.Create; // setup objects Conn.Provider := 'ADsDSOObject'; Conn.Open('Active Directory Provider', '', '', 0); Cmd.Set_ActiveConnection(Conn); Cmd.Properties.Item['Page Size'].Value := 1000; Cmd.Properties.Item['Searchscope'].Value := ADS_SCOPE_SUBTREE; RunQuery(edtQuery.Text); end;
Once again, the whole sample is available for download (ZIP, 36 Kb).
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Theme design by Jelle Druyts