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

50 Visitors Online


 
...list the user privileges (NT)?
Autor: Michael Wiren
[ Print tip ]  

Tip Rating (8):  
     


procedure TForm1.Button1Click(Sender: TObject);
const
  
TokenSize = 800; //  (SizeOf(Pointer)=4 *200)
var
  
hToken: THandle;
  pTokenInfo: PTOKENPRIVILEGES;
  ReturnLen: Cardinal;
  i: Integer;
  PrivName: PChar;
  DisplayName: PChar;
  NameSize: Cardinal;
  DisplSize: Cardinal;
  LangId: Cardinal;
begin
  
GetMem(pTokenInfo, TokenSize);
  if not OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
    hToken) then ShowMessage('OpenProcessToken error');
  if not GetTokenInformation(hToken, TokenPrivileges, pTokenInfo, TokenSize, ReturnLen) then
    
ShowMessage('GetTokenInformation error');
  GetMem(PrivName, 255);
  GetMem(DisplayName, 255);
  for i := 0 to pTokenInfo.PrivilegeCount - 1 do
  begin
    
DisplSize := 255;
    NameSize  := 255;
    LookupPrivilegeName(nil, pTokenInfo.Privileges[i].Luid, PrivName, Namesize);
    LookupPrivilegeDisplayName(nil, PrivName, DisplayName, DisplSize, LangId);
    ListBox1.Items.Add(PrivName +^I + DisplayName);
  end;
  FreeMem(PrivName);
  FreeMem(DisplayName);
  FreeMem(pTokenInfo);
end;

 

Rate this tip:

poor
very good


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