下面的代码是本坛子某个帖子里面的,出处不详了
function TWinSystem.SetPrivilege(
sPrivilegeName : string;
bEnabled : boolean )
: boolean;
var
TPPrev,
TP : TTokenPrivileges;
Token : THandle;
dwRetLen : DWord;
begin
Result := False;
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,Token );
TP.PrivilegeCount := 1;
if( LookupPrivilegeValue(
Nil,
PChar( sPrivilegeName ),
TP.Privileges[ 0 ].LUID ) )then
begin
if( bEnabled )then
begin
TP.Privileges[ 0 ].Attributes :=
SE_PRIVILEGE_ENABLED;
end else
begin
TP.Privileges[ 0 ].Attributes :=
0;
end;
dwRetLen := 0;
Result := AdjustTokenPrivileges(
Token,
False,
TP,
SizeOf( TPPrev ),
TPPrev,
dwRetLen );
end;
CloseHandle( Token );
end;
然后SetPrivilege( 'SeShutdownPrivilege', True )就可以获取关机权限
ExitWindowsEx 关机
SetSystemPowerState(True,True) 休眠