您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

Delphi创建删除查询Windows用户

时间:2011/9/3 15:38:03 点击:

  核心提示:unit SysFunctions;interfaceuses Windows,Classes;type USER_INFO_1 = record usri1_name: LPWSTR; usri1_...
unit SysFunctions;

interface
uses Windows,Classes;

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';
function getSysUser(var TStrsUsers:TStringList):integer;


implementation

function getSysUser(var TStrsUsers:TStringList):integer;
var
  EntiesRead: DWORD;
  TotalEntries: DWORD;
  UserInfo: lpUSER_INFO_1;
  lpBuffer: Pointer;
  ResumeHandle: DWord;
  Counter: Integer;
  NetApiStatus: LongWord;
begin
  if not Assigned(TStrsUsers) then
  begin
    Result:=-1;
    Exit;
  end;
  ResumeHandle := 0;
  repeat
  NetApiStatus := NetUserEnum(nil, 1, 0, lpBuffer, 0, EntiesRead,
  TotalEntries, ResumeHandle);
  UserInfo := lpBuffer;
  for Counter := 0 to EntiesRead - 1 do
  begin
    TStrsUsers.add(WideCharToString(UserInfo^.usri1_name) + '=' +
    WideCharToString(UserInfo^.usri1_comment));
    Inc(UserInfo);
  end;
  NetApiBufferFree(lpBuffer);
  until (NetApiStatus <> ERROR_MORE_DATA);
  Result:=0;
end;
end.

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2019 版权所有 All Rights Reserved.
  • 沪ICP备05001939号