www.pudn.com > UCtrl.rar > AdjustProc.pas
unit AdjustProc;
interface
uses Windows;
function AdProc(): Bool; stdcall;
//if AdjustProcessPrivilege(GetCurrentProcess, 'SeDebugPrivilege') then
implementation
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;
//更新进程令牌,成功返回TRUE
if AdjustTokenPrivileges(Token, False, TokenPri, sizeof(TokenPri), nil, l) then
Result := True;
end;
end;
end;
function AdProc(): Bool; stdcall;
begin
Result := AdjustProcessPrivilege(GetCurrentProcess, 'SeDebugPrivilege');
end;
end.