AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Active Directory: Benutzer/Computer mit Anlagedatum?
Thema durchsuchen
Ansicht
Themen-Optionen

Active Directory: Benutzer/Computer mit Anlagedatum?

Ein Thema von Sharky · begonnen am 15. Okt 2007 · letzter Beitrag vom 17. Okt 2007
Antwort Antwort
Benutzerbild von sakura
sakura

Registriert seit: 10. Jun 2002
Ort: Unterhaching
11.413 Beiträge
 
Delphi 12 Athens
 
#1

Re: Active Directory: Benutzer/Computer mit Anlagedatum?

  Alt 15. Okt 2007, 13:20
Hi Sharky,

fast einfach. Ein bissle ADO und eine spezielle Funktion (VBGetObject) erledigen die Aufgabe:
Delphi-Quellcode:
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);
Die Funktion VBGetObject:
Delphi-Quellcode:
function VBGetObject(const Name: AnsiString): IDispatch;
var
  BindContext: IBindCtx;
  Moniker: IMoniker;
  Eaten: Integer;
begin
  OleCheck(CreateBindCtx(0, BindContext));
  OleCheck(MkParseDisplayName(BindContext, PWideChar(WideString(Name)), Eaten, Moniker));
  OleCheck(Moniker.BindToObject(BindContext, nil, IDispatch, Result));
end;
Das Format der Query:
Zitat:
SELECT Name, ADsPath, whenCreated FROM 'LDAP://DC=fabrikam,DC=com' WHERE objectCategory='User'
bzw.
SELECT Name, ADsPath, whenCreated FROM 'LDAP://DC=fabrikam,DC=com' WHERE objectCategory='Computer'
Das volle Beispiel findest Du in meinem Blog
Daniel Lizbeth
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:02 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz