本文整理自网络,侵删。
//提升进程令牌函数
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 读文件到十六进制的函数(Delphi 7 下可用)
Delphi ado 连接 excel (附excel各个版本的版本号)
更多相关阅读请进入《Delphi》频道 >>