Advertisement
Gov_777

Перезапуск винды

May 30th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.03 KB | None | 0 0
  1. function WindowsExit(RebootParam: Longword): Boolean;
  2. var
  3.   TTokenHd: THandle;
  4.   TTokenPvg: TTokenPrivileges;
  5.   cbtpPrevious: DWORD;
  6.   rTTokenPvg: TTokenPrivileges;
  7.   pcbtpPreviousRequired: DWORD;
  8.   tpResult: Boolean;
  9. const
  10.   SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
  11. begin
  12.   if Win32Platform = VER_PLATFORM_WIN32_NT then
  13.   begin
  14.     tpResult := OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, TTokenHd);
  15.     if tpResult then
  16.     begin
  17.       tpResult := LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME, TTokenPvg.Privileges[0].Luid);
  18.       TTokenPvg.PrivilegeCount := 1;
  19.       TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
  20.       cbtpPrevious := SizeOf(rTTokenPvg);
  21.       pcbtpPreviousRequired := 0;
  22.       if tpResult then
  23.         AdjustTokenPrivileges(TTokenHd, False, TTokenPvg, cbtpPrevious, rTTokenPvg, pcbtpPreviousRequired);
  24.     end;
  25.   end;
  26.   Result := ExitWindowsEx(RebootParam, 0);
  27. end;
  28. //WindowsExit(EWX_REBOOT or EWX_FORCE);//применение для перезапуска
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement