获取NT用户列表

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
// The NetUserEnum function provides information about all user accounts on a server.
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';
{...}
procedure TForm1.Button1Click(Sender: TObject);
var
EntiesRead: DWORD;
TotalEntries: DWORD;
UserInfo: lpUSER_INFO_1;
lpBuffer: Pointer;
ResumeHandle: DWord;
Counter: Integer;
NetApiStatus: LongWord;
begin
ResumeHandle := 0;
repeat
// NetApiStatus := NetUserEnum(PChar('//NT-Domain'), 1, 0, lpBuffer, 0,EntiesRead, TotalEntries, ResumeHandle);
NetApiStatus := NetUserEnum(nil, 1, 0, lpBuffer, 0, EntiesRead,
TotalEntries, ResumeHandle);
UserInfo := lpBuffer;
for Counter := 0 to EntiesRead - 1 do
begin
listbox1.items.add(WideCharToString(UserInfo^.usri1_name) + ' --> ' +
WideCharToString(UserInfo^.usri1_comment));
Inc(UserInfo);
end;
NetApiBufferFree(lpBuffer);
until (NetApiStatus <> ERROR_MORE_DATA);
end;
 
 
后退
顶部