unit AdjPP;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Tlhelp32, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function AdjustProcessPrivilege(Token_Name: Pchar): Boolean;
var
Token: Cardinal;
TokenPri: TOKEN_PRIVILEGES;
ProcessDest: int64;
PreSta: DWORD;
begin
Result := False;
if OpenProcessToken(GetCurrentProcess,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;
PreSta := 0;
if AdjustTokenPrivileges(Token,False,TokenPri,sizeof(TokenPri),nil,PreSta) then begin
Result := True;
end;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Items.Add('程序开始运行');
if AdjustProcessPrivilege('SeDebugPrivilege') then begin
ListBox1.Items.Add('提升权限成功');
end else begin
ListBox1.Items.Add('提升权限失败');
end;
end;
end.