码迷,mamicode.com
首页 > Windows程序 > 详细

delphi 使电脑睡眠代码

时间:2019-09-03 16:32:47      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:令牌   message   www   com   token   sys   shutdown   ssd   shu   

//提升进程令牌函数
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 使电脑睡眠代码

标签:令牌   message   www   com   token   sys   shutdown   ssd   shu   

原文地址:https://www.cnblogs.com/blogpro/p/11453624.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!