type
USERINFO = record
name: LPWSTR;
password: LPWSTR;
password_age: DWORD;
priv: DWORD;
home_dir: LPWSTR;
comment: LPWSTR;
flags: DWORD;
script_path: LPWSTR;
end;
function NetUserEnum(ServerName: PWideChar; Level, Filter: DWORD;
var Buffer: Pointer; PrefMaxLen: DWORD; var EntriesRead, TotalEntries,
ResumeHandle: DWORD): Longword; stdcall; external 'netapi32.dll';
function NetApiBufferFree(pBuffer: PByte): Longint; stdcall;
external 'netapi32.dll';
procedure users(usrstr: TStrings);
var
NetApiStatus, Enties, Total, ResumeH: Cardinal;
Info: ^USERINFO;
Buffer: Pointer;
i: Integer;
begin
ResumeH := 0;
usrstr.Clear;
repeat
NetApiStatus := NetUserEnum(nil, 1, 0, Buffer, 0, Enties, Total, ResumeH);
Info := Buffer;
for i := 1 to Enties do
begin
usrstr.Add(WideCharToString(Info^.name));
Inc(Info);
end;
NetApiBufferFree(Buffer);
until (NetApiStatus <> ERROR_MORE_DATA);
end;
// Beispielaufruf
procedure TForm1.Button1Click(Sender: TObject);
begin
users(ListBox1.Items);
end;