program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, TlHelp32, PsAPI, Windows; function ProcessIsElevated(Process: Cardinal): Boolean; var hToken, hProcess : THandle; pTokenInformation: Pointer; ReturnLength: DWORD; TokenInformation: TTokenElevation; begin //hProcess := GetCurrentProcess; hProcess := Process; try if OpenProcessToken(hProcess, TOKEN_QUERY, hToken) then try TokenInformation.TokenIsElevated := 0; pTokenInformation := @TokenInformation; GetTokenInformation(hToken, TokenElevation, pTokenInformation, SizeOf(TokenInformation), ReturnLength); Result := (TokenInformation.TokenIsElevated > 0); finally CloseHandle(hToken); end; except Result := False; end; end; begin try { TODO -oUser -cConsole Main : Insert code here } Writeln(ProcessIsElevated(6972)); Writeln(ProcessIsElevated(1032)); readln; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); //delphiw.com end; end.
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.046639919281006 seconds