whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

17 Visitors Online


 
...get a list of users who are registered on the NT Workstation?
Autor: Henrik Jonsson
[ Print tip ]  

Tip Rating (5):  
     


// 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; stdcallexternal 'netapi32.dll';

function NetApiBufferFree(pBuffer: PByte): Longint; stdcallexternal
'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;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners