unit Unit2;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    ListBox2: TListBox;
    ListBox3: TListBox;
    ListBox4: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ListBox2DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var  r : TRegistry;

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 Sid2Text(Sid: PSID; var StringSid:STRING {Pchar}):boolean;


var
  Form1: TForm1;

implementation

{$R *.dfm}




function GetUserSid(const UserName: string): string;
var
  P: PSID;
  PRef, PName: PChar;
  RefSz, Sz: Cardinal;
  peUse: Cardinal;
  St1:string;
begin
  Sz:= 0; RefSz:= 0;
  PName:= PChar(UserName);
  PeUse:=SidTypeUser;
  LookupAccountName(nil, PName, nil, Sz, nil, RefSz, peUse);
  if GetLastError <> ERROR_INSUFFICIENT_BUFFER then RaiseLastOSError;
  GetMem(P, Sz + RefSz);
  try
    Cardinal(PRef):= Cardinal(P) + Sz;
    if not LookupAccountName(nil, PName, P, Sz, PRef, RefSz, peUse)
        then RaiseLastOSError;
    Sid2Text(p,St1);
    Result:= St1;
  finally
    FreeMem(P);
  end;
end;





Function Sid2Text(Sid: PSID; var StringSid:STRING {Pchar}):boolean;
var
 ida : Windows.PSIDIdentifierAuthority;
 l, subs : cardinal;
 s : string;
begin
 ida := GetSidIdentifierAuthority(sid);
 subs := GetSidSubAuthorityCount(sid)^;

 s := 'S-' + IntToStr(PByte(sid)^)  + '-';
 if (ida.Value[0] <> 0) or (ida.Value[1] <> 0) then
 begin
   s := s + '0x';
   for l := 0 to 5 do
     s := s + IntToHex(ida.value[l], 2);
 end
 else
 begin
   s := s + IntToStr( ida.value[5] +
                      (ida.value[4] shl 8) +
                      (ida.value[3] shl 16) +
                      (ida.value[2] shl 24));
 end;

 for l := 0 to subs-1 do
   s := s + '-' + IntToStr(GetSidSubAuthority(sid, l)^);
   StringSid:=s;
end;
{---------------------}



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);
listbox1.Items.SaveToFile(pathstarts+'1.txt');
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
r:=TRegistry.Create(KEY_READ);
R.RootKey:=HKEY_USERS;
Pathstartsinit;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i1:integer;St1,st2:String;
begin




for i1:=0 to ListBox1.Count-1 do
begin
St1:=tNfi(1,ListBox1.Items[i1]);
St2:=GetUserSid(St1);
ListBox2.Items.Add(St1+'|'+St2);
if r.Openkey (St2+'\Software\Microsoft\Windows\CurrentVersion\Run',False) then
begin
    ListBox3.Items.Add(St1);
end;
r.CloseKey;
listbox2.Items.SaveToFile(pathstarts+'2.txt');

Application.ProcessMessages;
end;


{FreeMem(UserDomain);
 FreeMem(UserSid);
 FreeMem(UserName);
 }
end;

procedure TForm1.ListBox2DblClick(Sender: TObject);
var St1:string; S: TStringList;i1:integer;

begin
St1:=tNFi(2,Listbox2.Items[Listbox2.itemindex]);
 S := TStringList.Create;
 ListBox4.Clear;
R.RootKey:=HKEY_USERS;
r.CloseKey;
if R.OpenKey(St1+'\Software\Microsoft\Windows\CurrentVersion\Run',False) then
    R.GetValueNames(S) else showMessage(St1+'\Software\Microsoft\Windows\CurrentVersion\Run');
for i1:=0 to s.Count-1 do ListBox4.Items.Add(s.Strings[i1]);
 s.Free;
end;

end.
