Thema: Delphi Liste der Domain-User

Einzelnen Beitrag anzeigen

Madlax

Registriert seit: 30. Aug 2004
Ort: Erkelenz
9 Beiträge
 
Delphi 7 Enterprise
 
#7

Re: Liste der Domain-User

  Alt 9. Aug 2005, 13:34
Hallo UweR,

ich habe eben mal meine Sources durchgeschaut und habe was gefunden, dass dir wahrscheinlich helfen wird. Dabei handelt es sich um eine Funktion die dir alle User in einer Domäne per ADOQuery zusammensammelt.

Delphi-Quellcode:
Uses ActiveDS_TLB;

//Binds to an ADSI object using the current credentials.
Function ADsGetObject( lpszPathName: WideString;
                       Const riid : TGUID;
                         Out ppObject ): HRESULT; Safecall;

Function ADsGetObject; External 'activeds.dll';

Function GetObject( Path: String ): IDispatch;
Begin
  ADsGetObject( Path, IDispatch, Result );
End; {Of GetObject}

Procedure TfrmADSIx.Users;
Var iAdRootDSE : IADs;
    Conn : TADOConnection;
    Data : TADODataSet;
    Cmd : TADOCommand;
    varDefaultNC: Variant;
    strQuery : String;
Begin
  //Find users by searching Active Directory.
  //This can be run from any DSClient-enabled computer.
  Conn := TADOConnection.Create( NIL );
  Data := TADODataSet.Create( NIL );
  Cmd := TADOCommand.Create( NIL );

  //Get the default naming context.
  iAdRootDSE := GetObject( 'LDAP://RootDSE' ) As IADs;
  varDefaultNC := iAdRootDSE.Get( 'defaultNamingContext' );

  //Open the connection.
  Conn.Provider := 'ADsDSOObject';
  Conn.LoginPrompt := False;
  Conn.Open;
    
  //Build the query to find all of the users.
  strQuery := '<LDAP://' + varDefaultNC + '>;(objectClass=user);name;subtree';

  Cmd.Connection := Conn;
  Cmd.ParamCheck := False;
  Cmd.CommandText := strQuery;
  Data.Recordset := Cmd.Execute;

  //Iterate through the results.
  While Not Data.Eof Do Begin
      ShowMessage( 'Name: ' + Data.FieldByName( 'name' ).AsString );
      Data.Next;
  End;

  //Clean up.
  Data.Free;
  Cmd.Free;
  Conn.Free;
  iAdRootDSE := NIL;
End; {Of Users}
In diesem Beispiel wurde activeds.dll als Typbibliothek nach Delphi importiert.
Die Funktion "ADsGetObject" befindet sich ebenfalls in dieser Dll, nähere Infos dazu findest du im MSDN.
Gruß,
Madlax
  Mit Zitat antworten Zitat