Q&A

  • [질문] 모든 사용자 계정 가져오기
help 아무리 봐도 모르겠던디...도와주삼.
1  COMMENTS
  • Profile
    구창민 2009.07.08 00:52
    안녕하세요..
    Windows 사용자 계정을 말씀하시는거지요?..
    아래코드를 참고해보세요..

    unit Unit7;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;

    type
    TForm7 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    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';

    var
    Form7: TForm7;

    implementation

    {$R *.dfm}

    procedure TForm7.Button1Click(Sender: TObject);
    var
    ERead: DWORD;
    TotalEntries: DWORD;
    UserInfo: lpUSER_INFO_1;
    lpBuffer: Pointer;
    ResumeHandle: DWORD;
    Counter: Integer;
    NetApiStatus: LongWord;
    begin
    ResumeHandle := 0;
    repeat
    NetApiStatus := NetUserEnum(nil, 1, 0, lpBuffer, 0, ERead, TotalEntries, ResumeHandle);
    UserInfo := lpBuffer;
    for Counter := 0 to ERead - 1 do
    begin
    Memo1.Lines.Add(WideCharToString(UserInfo^.usri1_name) + ' -> ' +
    WideCharToString(UserInfo^.usri1_comment));
    Inc(UserInfo);
    end;
    NetApiBufferFree(lpBuffer);
    until (NetApiStatus <> ERROR_MORE_DATA);
    end;


    end.