本文整理自网络,侵删。
//提升进程令牌函数
function AdjustProcessPrivilege(ProcessHandle:THandle;Token_Name:Pchar):boolean;
var
Token:THandle;
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;
//
if AdjustProcessPrivilege(GetCurrentProcess,'SeShutdownPrivilege') then//提升权限
begin
//showmessage('ok');
SetSystemPowerState(false,TRUE); //电脑进入睡眠状态 www.delphitop.com
end
else
begin
//showmessage('no');
end;
相关阅读 >>
Delphi recodedatetime、recodedate、recodetime、recodeyear ... 修改时间
Delphiwindows 下编译 exe 文件时把一个外部 txt 文件编译到 exe 里面
Delphi xe 在andriod程序中获取外置sd卡根目录
更多相关阅读请进入《Delphi》频道 >>