Einzelnen Beitrag anzeigen

eicky
(Gast)

n/a Beiträge
 
#1

Beispielaufruf von NetQueryDisplayInformation

  Alt 23. Jun 2006, 08:43
Hi

Aus meiner ursprünglichen Frage ist inzwischen fertiger Code geworden, um alle Computerconten einer NT-Domäne bzw. eines Active Directory zu bekommen:

Delphi-Quellcode:
type
  NET_DISPLAY_MACHINE = record
    usri2_name : PWideChar;
    usri2_comment : PWideChar;
    usri2_flags : Cardinal;
    usri2_user_id : Cardinal;
    usri2_next_index : Cardinal;
  end;
  PNET_DISPLAY_MACHINE = ^NET_DISPLAY_MACHINE;

const
  NERR_Success = 0;
  ERROR_MORE_DATA = 234;

function NetQueryDisplayInformation(ServerName: PWideChar;
                                    Level, Index, EntriesRequested,
                                    ReferredMaximumLength: Cardinal;
                                    var ReturnedEntryCount: Cardinal;
                                    var SortedBuffer: Pointer): Cardinal;
                                    stdcall; external 'Netapi32.dll';
function NetApiBufferFree(Buffer : Pointer): Cardinal; stdcall;
                           external 'NETAPI32.dLL';

function ListComputerAccounts(sServerName: PWideChar; Output:TStrings):integer;
var
   total, res, count, index: Cardinal;
   sBuffer: Pointer;
   ComputerAccounts: PNET_DISPLAY_MACHINE;
begin
  Output.clear;
  index := 0;
  res := 0;
  repeat
    res := NetQueryDisplayInformation(sServerName, 2, index, 100, High(Cardinal), total, sBuffer);
    showmessage(inttostr(res));
    if (res = NERR_Success) or (res=ERROR_MORE_DATA) then
    begin
      ComputerAccounts := @sBuffer^;
      while total > 0 do
      begin
        Output.Add(StringReplace(String(ComputerAccounts^.usri2_name), '$', '', [rfReplaceAll]));
        index := ComputerAccounts^.usri2_next_index;
        Dec(total);
        inc(ComputerAccounts);
      end;

    end;
    NetApiBufferFree(sBuffer);
  until res <> ERROR_MORE_DATA;
end;
Hier ein Beispielaufruf:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ListComputerAccounts('\\servername', ListBox1.Items);
end;
Gruß,

Eicky
  Mit Zitat antworten Zitat