delphi 使电脑睡眠代码
2021-02-05 00:14
标签:令牌 message www com token sys shutdown ssd shu delphi 使电脑睡眠代码 标签:令牌 message www com token sys shutdown ssd shu 原文地址:https://www.cnblogs.com/blogpro/p/11453624.html//提升进程令牌函数
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;
下一篇:C#是什么?