怎样在计算机开机后两小时自动关机(两小时内一直在玩游戏

解决方案 »

  1.   

    写用time
    记录时间差。。然后关机!//下边是个关机程序。。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);  private
        { Private declarations }
        procedure AdjustToken;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.AdjustToken();
    var
      hdlProcessHandle : Cardinal;
      hdlTokenHandle : Cardinal;
      tmpLuid : Int64;
      tkpPrivilegeCount : Int64;
      tkp : TOKEN_PRIVILEGES;
      tkpNewButIgnored : TOKEN_PRIVILEGES;
      lBufferNeeded : Cardinal;
      Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;
    begin
             hdlProcessHandle := GetCurrentProcess;
             OpenProcessToken(hdlProcessHandle,
                             (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY),
                              hdlTokenHandle);         // Get the LUID for shutdown privilege.
             LookupPrivilegeValue('', 'SeShutdownPrivilege', tmpLuid);
             Privilege[0].Luid := tmpLuid;
             Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;
             tkp.PrivilegeCount := 1;   // One privilege to set
             tkp.Privileges[0] := Privilege[0];
             // Enable the shutdown privilege in the access token of this
             // process.
             AdjustTokenPrivileges(hdlTokenHandle,
                                   False,
                                   tkp,
                                   Sizeof(tkpNewButIgnored),
                                   tkpNewButIgnored,
                                   lBufferNeeded); end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
         AdjustToken;
         ExitWindowsEx((EWX_SHUTDOWN Or EWX_FORCE Or EWX_REBOOT), $FFFF);
    end;end.