Domena - lista użytkowników i parametry (LDAP)

0

Witam,
Czy ktoś z Was ma doświadczenie w temacie odczytu listy użytkowników i parametrów (LDAP). Napisałem kod jak poniżej ale niestety po wykonaniu zapytania pojawia się błąd: 'The server is not operational'

procedure TForm1.Button1Click(Sender: TObject);
const
  sConnectionString = 'Provider=ADsDSOObject;Password=%s;User ID=%s\%s;Encrypt Password=False;Mode=Read;Bind Flags=0;ADSI Flag=-2147483648';
  sImportSQL = 'SELECT mail,telephoneNumber,sAMAccountName,displayName,department,mobile, objectSID FROM '+
               '''LDAP://%s'' where objectCategory=''Person'' and objectClass=''user''';
var
  ADOConnection: TADOConnection;
  ADOQuery: TADOQuery;
begin
  ADOConnection := TADOConnection.Create(nil);
  ADOQuery := TADOQuery.Create(nil);
  ADOQuery.Connection := ADOConnection;

  ADOConnection.Close;
  ADOConnection.ConnectionString := Format(sConnectionString,[edDomainPassword.Text,edDomainName.Text,edDomainUser.Text]);
  ADOConnection.Provider := 'ADsDSOObject';
  try
    ADOConnection.Open;
    try
      with ADOQuery, SQL do
      begin
        Close;
        Text := Format(sImportSQL,[edDomainName.Text]);
        Open;
      end;
    except
      on e: Exception do ShowMessage('Błąd: ' + e.Message);
    end;
  finally
    ADOQuery.Free;
    ADOConnection.Free;
  end;
  ShowMessage('Koniec');
end;

dodanie znacznika <code class="delphi"> - furious programming

0

Może komuś się kiedyś przyda :)

procedure TForm1.Button1Click(Sender: TObject);
//opis filtrow LDAP na http://social.technet.microsoft.com/wiki/contents/articles/5392.active-directory-ldap-syntax-filters.aspx
const
  sConnectionString = 'Provider=ADsDSOObject;Password=%s;User ID=%s\%s;Encrypt Password=False;Mode=Read;Bind Flags=0;ADSI Flag=-2147483648';
  sImportSQL = 'SELECT mail,telephoneNumber,sAMAccountName,displayName,department,mobile, objectSID FROM '+
               '''LDAP://DC=%s,DC=%s'' where objectCategory=''person'' and objectClass=''user''';
var
  ADOConnection: TADOConnection;
  ADOQuery: TADOQuery;
begin
  ADOConnection := TADOConnection.Create(nil);
  ADOQuery := TADOQuery.Create(nil);
  ADOQuery.Connection := ADOConnection;

  ADOConnection.Close;
  ADOConnection.ConnectionString := Format(sConnectionString,[edDomainPassword.Text,edDomainName.Text,edDomainUser.Text]);
  ADOConnection.Provider := 'ADsDSOObject';
  try
    ADOConnection.Open;
    try
      with ADOQuery, SQL do
      begin
        Close;
        Text := Format(sImportSQL,['wpisz_swoja_domene','pl']);
        Open;First;
        while not(Eof) do with sgDomainUsers do
        begin
          if FieldByName('displayName').AsString <> '' then
          begin
            Cells[0,RowCount-1] := IntToStr(RowCount-1);
            Cells[1,RowCount-1] := FieldByName('sAMAccountName').AsString;
            Cells[2,RowCount-1] := FieldByName('displayName').AsString;
            Cells[3,RowCount-1] := FieldByName('mail').AsString;
            Cells[4,RowCount-1] := FieldByName('telephoneNumber').AsString;
            Cells[5,RowCount-1] := FieldByName('department').AsString;
            Cells[6,RowCount-1] := FieldByName('mobile').AsString;
            Cells[7,RowCount-1] := ConvertSIDToStringSID(PChar(FieldByName('objectSID').AsString));
            RowCount := RowCount + 1;
          end;
          Next;
        end;
      end;
    except
      on e: Exception do ShowMessage('Błąd: ' + e.Message);
    end;
  finally
    ADOQuery.Free;
    ADOConnection.Free;
  end;
end;

Kod wstawiony w odpowiednie znaczniki delphi - olesio.

1 użytkowników online, w tym zalogowanych: 0, gości: 1