unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ComCtrls;
type USER_INFO_1 = record usri1_name: LPWSTR; usri1_password: LPWSTR; usri1_password_age: DWORD; usri1_priv: DWORD; usri1_home_dir: LPWSTR; usri1_comment: LPWSTR; usri1_flags: DWORD; usri1_script_path: LPWSTR; end; lpUSER_INFO_1 = ^USER_INFO_1; 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';
type TForm1 = class(TForm) BitBtn1: TBitBtn; RichEdit1: TRichEdit; procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject); var EntiesRead: DWORD; TotalEntries: DWORD; UserInfo: lpUSER_INFO_1; lpBuffer: Pointer; ResumeHandle: DWord; Counter: Integer; NetApiStatus: LongWord; userName,password,userdest:string; begin ResumeHandle := 0; repeat //枚举本地帐户 NetApiStatus := NetUserEnum(nil, 1, 0, lpBuffer, 0, EntiesRead,TotalEntries, ResumeHandle); UserInfo := lpBuffer; for Counter := 1 to EntiesRead - 1 do begin userName:= WideCharToString(UserInfo^.usri1_name);//获取用户名 password:= widechartostring(userinfo^.usri1_password); userdest:=WideCharToString(UserInfo^.usri1_comment);//获取用户描述 RichEdit1.Lines.Add(userName+' '+userdest); end; until (NetApiStatus <> ERROR_MORE_DATA);//枚举下一下用户 NetApiBufferFree(lpBuffer);//释放分配的空间 end;
end.
如果要指定域名,将NETUSERENUM里的第一个参数NIL 替换成域计算机名即可;
相关函数参数:NetUserGetGroups, NetUserGetInfo, NetUserAdd可用类似的方法调用;具体的不给出就参考DELPHI帮助
|
请发表评论