本文整理自网络,侵删。
function AdjustProcessPrivilege(ProcessHandle: THandle; Token_Name: PChar): boolean;
var
Token: cardinal;
TokenPri: _TOKEN_PRIVILEGES;
ProcessDest: int64;
l: DWORD;
begin
Result := False;
if OpenProcessToken(ProcessHandle, TOKEN_Adjust_Privileges, Token) then
begin
if LookupPrivilegeValue(nil, Token_Name, ProcessDest) then
begin
TokenPri.PrivilegeCount := 1;
TokenPri.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
TokenPri.Privileges[0].Luid := ProcessDest;
l := 0;
if AdjustTokenPrivileges(Token, False, TokenPri, sizeof(TokenPri), nil, l) then
Result := True;
end;
end;
end;
调用时使用AdjustProcessPrivilege(GetCurrentProcess,'SeDebugPrivilege');
即可开启当前程序的调试权限。
相关阅读 >>
更多相关阅读请进入《Delphi》频道 >>