Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to get WIN NT/2000 user account list with Delphi??

LamSirLamSir Member Posts: 11
Who can help me?? pls post ur code or provide the sample.
Thanks in advance:)

Comments

  • Filip PoverudFilip Poverud Member Posts: 27
    What user accounts ... on the local client or on the nearest DC ?

    ---

    Regards

    /Filip
  • LamSirLamSir Member Posts: 11
    Hi,Filip,
    Thx a lot for ur kindly attention,it's local NT/2000 user account list,
    I wanna export those user account list into another Application program.
    Do u have any ideaes for this questions?
    Thanks & regards!!:)

    : What user accounts ... on the local client or on the nearest DC ?
    :
    : ---
    :
    : Regards
    :
    : /Filip
    :

  • Filip PoverudFilip Poverud Member Posts: 27
    Having Servername as '' returns the local client.

    ---

    unit Unit1;

    interface

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

    type
    USER_INFO_10 = packed record
    usri10_name: LPWSTR;
    usri10_comment: LPWSTR;
    usri10_usr_comment: LPWSTR;
    usri10_full_name: LPWSTR;
    end;
    PUSER_INFO_10 = ^USER_INFO_10;

    function NetUserEnum (Servername: LPCWSTR;
    Level: DWORD;
    Filter: DWORD;
    Buf: PUSER_INFO_10;
    PrefMaxLen: DWORD;
    EntriesRead: LPDWORD;
    TotalEntries: LPDWORD;
    Resume_Handle: LPDWORD
    ): DWORD;
    stdcall;
    external 'netapi32.dll';

    function NetApiBufferFree (Buffer: Pointer
    ): DWORD;
    stdcall;
    external 'netapi32.dll';

    type
    TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    function GetAccountList(ServerName: string; ListBox: TListBox): TListBox;
    var
    Buffer,
    TmpBuffer : Pointer;
    PrefMaxLen : Integer;
    Resume_Handle,
    EntriesRead,
    TotalEntries : DWORD;
    I,
    Size : Integer;
    Account,
    FullName,
    Comment : string;
    PSrvr : PWideChar;
    begin
    Result := ListBox;
    Result.Clear;
    Result.Columns := 3;
    Result.TabWidth := Result.Width div 4 - 20;

    try
    Size := Length (ServerName);
    GetMem(PSrvr,Size * SizeOf(WideChar) + 1);
    StringToWideChar(ServerName,PSrvr,Size + 1);

    PrefMaxLen := -1;
    EntriesRead := 0;
    TotalEntries := 0;
    Resume_Handle := 0;

    if NetUserEnum (PSrvr, 10, $0002, @Buffer, PrefMaxLen, @EntriesRead, @TotalEntries, @Resume_Handle) = S_OK then
    begin
    TmpBuffer := Buffer;

    for I := 0 To TotalEntries - 1 do
    begin
    Account := PUSER_INFO_10(TmpBuffer).usri10_name;
    FullName := PUSER_INFO_10(TmpBuffer).usri10_full_name;
    Comment := PUSER_INFO_10(TmpBuffer).usri10_comment;

    Resume_Handle := 0;

    Result.Items.Add(Account + ^I + FullName + ^I + Comment);

    TmpBuffer := Pointer (DWORD (TmpBuffer) + SizeOf (USER_INFO_10));
    end;

    end;

    finally
    NetApiBufferFree (Buffer);
    end;

    FreeMem(PSrvr);
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    GetAccountList('', ListBox1);
    end;

    end.

    ---

    Regards

    /Filip
  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    ________ || http://forcoder.org || free video tutorials and ebooks about { JavaScript, Scratch, Objective-C, Go, Perl, Swift, Python, Visual Basic, C++, PHP, Assembly, C#, Java, R, Ruby, PL/SQL, MATLAB, Delphi, C, Visual Basic .NET COBOL, Crystal, Ada, Rust, FoxPro, Julia, Transact-SQL, ML, ABAP, Lisp, Erlang, Lua, Alice, Apex, Scala, Bash, LabVIEW, Awk, VBScript, F#, D, Hack, Fortran, Scheme, Dart, Kotlin, Prolog, SAS, Clojure, Logo } ___________

Sign In or Register to comment.