其他分享
首页 > 其他分享> > delphi 强制重启计算机

delphi 强制重启计算机

作者:互联网

unit uFuncs;

interface
uses
  windows;
procedure GetPrivilege;
procedure RebootSystem();
implementation
procedure RebootSystem();
begin
  GetPrivilege;
  //initiateSystemShutDown();显示关机提示;
  //ExitWindowsEx(EWX_SHUTDOWN+EWX_FORCE+EWX_POWEROFF+EWX_FORCEIFHUNG, 0); //强制关机
  ExitWindowsEx(EWX_REBOOT OR EWX_FORCE or EWX_POWEROFF or EWX_FORCEIFHUNG, 0);  // 重启
end;
procedure GetPrivilege;
var
  NewState:       TTokenPrivileges;
  lpLuid:         Int64;
  ReturnLength:   DWord;
  ToKenHandle:    THandle;
begin
  OpenProcessToken(GetCurrentProcess,
                   TOKEN_ADJUST_PRIVILEGES
                   OR TOKEN_ALL_ACCESS
                   OR STANDARD_RIGHTS_REQUIRED
                   OR TOKEN_QUERY,ToKenHandle);
  LookupPrivilegeValue(nil,'SeShutdownPrivilege',lpLuid);
  NewState.PrivilegeCount:=1;
  NewState.Privileges[0].Luid:=lpLuid;
  NewState.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
  ReturnLength:=0;
  AdjustTokenPrivileges(ToKenHandle,False,NewState,0,nil,ReturnLength);
end;
end.

 

标签:ReturnLength,NewState,delphi,lpLuid,EWX,GetPrivilege,强制,重启,procedure
来源: https://blog.csdn.net/byc6352/article/details/94839854