Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#7

Re: Liste aller Windows-Benutzer

  Alt 18. Nov 2005, 23:47
Ich habe den Source gerade vor mir:

Delphi-Quellcode:
function NetUserEnum(servername: LPCWSTR; level: DWORD; filter: DWORD; var
  buf: Pointer; prefmaxlen: DWORD; var entriesred: DWORD; var totalentries:
  DWORD; resumehandle: PDWORD): NET_API_STATUS; stdcall;

//...

implementation

const
  netapi32lib = 'netapi32.dll';

function NetUserEnum; external netapi32lib name 'NetUserEnum';
Delphi-Quellcode:
type
  NET_API_STATUS = DWORD;
  TStringArray = array of WideString;

const
  NERR_Success = 0;
Delphi-Quellcode:
////////////////////////////////////////////////////////////////////////////////
// Procedure : EnumUsers
// Comment : Enumerates all users on the local machine

function EnumUsers(const Server: WideString; filter: DWORD): TStringArray;
var
  ui1, pWork : Pointer;
  EntriesRead, EntriesTotal: DWORD;
  NetError : DWORD;
  Loop : Integer;
begin
  ui1 := nil;
  pWork := nil;
  if Server <> 'then
  begin
    try
      NetError := NetUserEnum(PWideChar(Server), 0, filter, ui1,
        MAX_PREFERRED_LENGTH, EntriesRead, EntriesTotal, nil);
      if (NetError = NERR_SUCCESS) and (EntriesRead > 0) then
      begin
        pWork := ui1;
        SetLength(Result, EntriesRead);
        for Loop := 0 to EntriesRead - 1 do
        begin
          Result[Loop] := PUserInfo1(ui1)^.usri1_name;
          Inc(Integer(ui1), sizeof(Pointer));
        end;
      end;
    finally
      NetApiBufferFree(pWork);
    end;
  end;
end;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat