unit UExitOnce;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses registry;
procedure TForm1.Button1Click(Sender: TObject);
var registr:TRegistry;
    hToken: THandle;
    Luid: TLargeInteger;
    tkp: TTokenPrivileges;
    ReturnLength: Cardinal;
    F: file;
begin
// перезагрузка компьютера
 if OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES,
                    hToken)
 then begin
  LookupPrivilegeValue(nil, 'SeShutdownPrivilege', Luid);
  tkp.Privileges[0].Luid := Luid;
  tkp.PrivilegeCount:=1;
  tkp.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
  if AdjustTokenPrivileges(hToken, False, tkp, 0, nil,
                           ReturnLength)
   then if not ExitWindowsEx(EWX_REBOOT, 0)
    then ShowMessage('Не удалось выключить компьютер');
 end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 Close;
end;

end.
