unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Menus,Registry, jpeg;type
  TMINI20100720 = class(TForm)
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    GroupBox1: TGroupBox;
    Edit2: TEdit;
    Button4: TButton;
    Timer1: TTimer;
    Timer2: TTimer;
    Label5: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  MINI20100720: TMINI20100720;
  time:Integer;
  timeInt,timeInt1,timeInt2:Integer;
  str,str1:String;
  times:Integer;
  timet1,timet2:Integer;
  f :TextFile;
 passward:String;
implementation{$R *.dfm}procedure SetAutorun(aProgTitle,aCmdLine: string; aRunOnce: boolean );
    var
    hKey: string;
    hReg: TRegIniFile;
begin
    if aRunOnce then
      hKey := 'Once' //程序只自动运行一次
    else
      hKey := '';
    hReg := TRegIniFile.Create('');//TregIniFile类的对象需要创建
    hReg.RootKey := HKEY_LOCAL_MACHINE;//设置根键
    hReg.WriteString('Software\Microsoft\Windows\CurrentVersion\Run'
                  + hKey + #0, aProgTitle, aCmdLine );//程序名称,可以为自定义值
                  //命令行数据,必须为该程序的绝对路径+程序完整名称
    hReg.destroy;
//释放创建的hReg
end;
procedure TMINI20100720.Button1Click(Sender: TObject);
begin
     passward:= Edit1.Text;
     if passward='xinmu1314'then
     begin
      Button3.Visible:=true;
    Button2.Visible:=true;
    Button1.SetFocus;
    Timer1.Enabled:=false;
     end;
     if passward<>'xinmu1314'then
     begin
     end;
end;procedure TMINI20100720.Timer1Timer(Sender: TObject);   //登入时间
begin
{ if Edit1.Text='laopo520'then
 begin
  Button1.SetFocus;
 end;
 }
 Label5.Caption:=timetostr(now);
  if time=0 then
  begin
    Timer2.Enabled:=true;
    Label4.Caption:='时间到!' ;
  end;
  if time<>0 then
  begin
  time:=time-1;
  end;end;
procedure DisableTaskmgr(Key: Boolean);
  Var  Reg:TReGIStry;
  Begin
  Reg:=TRegistry.Create;
  try
  Reg.RootKey := HKEY_CURRENT_USER;
  if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Policies\System', True) then
  begin
  if Key then
  Reg.WriteString('DisableTaskMgr','1')
  else
  Reg.WriteInteger('DisableTaskMgr',0);
  Reg.CloseKey;
  end;
  except
  Reg.Free;
  end;
  end;
procedure TMINI20100720.FormCreate(Sender: TObject);
 var
    DateTime:TDateTime;
    s:String;
    stime:string;
    hn : HWnd; begin
 SetAutorun(Application.Title,application.ExeName,false);
 hn := FindWindowEx(FindWindowEx(FindWindow('Shell_TrayWnd',nil),0,
            'TrayNotifyWnd',nil),0,'TrayClockWClass',nil);
  if hn <> 0 then
    ShowWindow(hn,SW_HIDE);
      hn := FindWindowEx(FindWindowEx(FindWindow('Shell_TrayWnd',nil),0,
           'TrayNotifyWnd',nil),0,'TrayClockWClass',nil); 
  if hn <> 0 then 
    ShowWindow(hn,SW_SHOW);
      timet1:=9;
      timet2:=16;
      DateTime:=now;
      Delete(str,3,8);
      Edit1.Text:=str;
      Timer1.Enabled:=true;
      time:=60; //一分钟输入
      if FileExists('..\abc.txt') then
      begin
           AssignFile(f,'..\abc.txt');
           reset(f);
           readln(f,s);
           closefile(f);
           Label3.Caption:='您原先设定的时间为:'+s;
           Edit2.Text:=s;
           times:=strtoint(s);      end;
      if FileExists('..\abc.txt')=false then
          begin
              times:=21;
             Label3.Caption:='您还未设定时间,初始时间为:'+inttostr(times);
      end;
      showwindow(application.handle,sw_hide);//任务栏看不到
      setwindowlong(application.handle,gwl_exstyle,
      getwindowlong(application.handle,gwl_exstyle)
      or ws_ex_toolwindow and not ws_ex_appwindow);
       DisableTaskmgr(true);
      // Label3.Caption:='您原先设定的时间为!!!'+inttostr(times);
end;procedure TMINI20100720.Timer2Timer(Sender: TObject); //时间范围
var
    rl: Cardinal;
    hToken: Cardinal;
    tkp: TOKEN_PRIVILEGES;
    mytime:TSystemTime;
    DateTime:TDateTime;
    strlast:string;
    I:integer;
    B:Boolean;
begin
      DateTime:=now;          //获取时间
      str:=TimeToStr(DateTime);
      str1:=str;      Delete(str1,2,9);
      timeInt1:=StrToInt(str1);
      if timeInt1 = 9 then
         begin
               timeInt := timeInt1;
         end;
               Delete(str,3,8);
               strlast := str;
               B := TryStrToInt(str, I);
      if B = true then
         begin
               timeInt := I;
         end;
      if (timeInt=times) or ((timeInt>=timet1)and (timeInt<timet2)) then   //是否在该时间里面
         begin
               Label3.Caption:='      在时间范围内';
         end
      else
         begin
            Label3.Caption:='系统自动关机';
            OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken);
            if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then
               begin
                  tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
                  tkp.PrivilegeCount := 1;
                  AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);
                  ExitWindowsEx(EWX_FORCE+1,0);
               end;  
         end;
end;procedure TMINI20100720.Button2Click(Sender: TObject);
begin
      MINI20100720.Close;
end;procedure TMINI20100720.Button3Click(Sender: TObject);
begin
      GroupBox1.Visible:=true;
end;procedure TMINI20100720.Button4Click(Sender: TObject);
var
    str:String;
    s:string;
begin
        str:=Edit2.Text;
        AssignFile(f,'..\abc.txt');
        Rewrite(f);
        Append(f);
        Writeln(f,str);
        closefile(f);
        AssignFile(f,'..\abc.txt');
        reset(f);
        readln(f,s);
        closefile(f);
        GroupBox1.Visible:=false;
      //  timet:=strToint(s);
      //  Label3.Caption:='您设定的时间为:'+str;
end;procedure TMINI20100720.Edit1Change(Sender: TObject);
begin
 if Edit1.Text='xinmu1314'then
 begin
  Button1.SetFocus;
 end;
 end;
end.