unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, NetServer;
type
NetAPIStatus = Integer;
TForm1 = class(TForm)
Button2: TButton;
lvUsers: TListView;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Users : TStringList;
end;
USER_INFO_0 = record
usri0_name : PWideChar;
end;
PUSER_INFO_0 = ^USER_INFO_0;
USER_INFO_20 = record
usri20_name : PWideChar;
usri20_full_name : PWideChar;
usri20_comment : PWideChar;
usri20_flags : Integer;
usri20_user_id : Integer
end;
PUSER_INFO_20 = ^USER_INFO_20;
var
Form1: TForm1;
function NetUserEnum (serverName : PWideChar; level, filter : Integer; var buffer : Pointer; prefmaxlen : Integer; var entriesRead, totalEntries, resumeHandle : Integer) : integer; stdcall;
implementation
function NetUserEnum; external 'NETAPI32.DLL';
{$R *.DFM}
procedure TForm1.Button2Click(Sender: TObject);
var
rv : NetAPIStatus;
buffer : pointer;
i, entriesRead, totalEntries : Integer;
p : PUSER_INFO_20;
p2 : PChar;
st : string;
wServerName:string;
NIL_HANDLE : Integer absolute 0;
begin
Users := TStringList.Create;
users.Clear;
wServerName := '';
rv := NetUserEnum (PWideChar (wServerName), 20, $0002, buffer, -1,
entriesRead, totalEntries, NIL_HANDLE);
p := PUSER_INFO_20 (buffer);
for i := 0 to entriesRead - 1 do
begin
st := p^.usri20_name;
st := st + #0;
st := st + p^.usri20_full_name + #0 + p^.usri20_comment;
users.Add (st);
Inc (p)
end ;
lvUsers.Items.BeginUpdate;
try
lvUsers.Items.Clear;
for i := 0 to users.count - 1 do
with lvUsers.Items.Add do
begin
p2 := @users [1];
Caption := p2;
Inc (p2, lstrlen (p2) + 1);
SubItems.Add (p2);
Inc (p2, lstrlen (p2) + 1);
SubItems.Add (p2);
end;
if lvUsers.Items.Count > 0 then
lvUsers.Selected := lvUsers.Items [0];
finally
lvUsers.Items.EndUpdate
end;
end;
end.
取得本机所有账号
转自盟动力
源码地址:http://www.tomore.com/1/39471.html