作者在 2010-02-05 13:12:50 发布以下内容
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Timer2: TTimer;
Timer3: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
private
procedure GetPrivilege;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.GetPrivilege;
var
NewState: TTokenPrivileges;
lpLuid: Int64;
ReturnLength: DWord;
ToKenHandle: Cardinal;
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;
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=True;
Timer2.Enabled:=True;
Timer3.Enabled:=True;
BorderStyle := bsNone;
Brush.Style := bsClear;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (TimeToStr(Time)>'23:30:00') or (TimeToStr(Time)<'11:30:00') then
begin
GetPrivilege;
ExitWindowsEx(EWX_SHUTDOWN OR EWX_POWEROFF, 0); //关机过程
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
if TimeToStr(Time) ='23:15:00' then
showMessage('为了你的健康,请及时关机睡觉'); //消息的实现过程
end;
procedure TForm1.Timer3Timer(Sender: TObject);
begin
Form1.Hide;
end;
end.