当前位置:文档之家› 定时关机代码

定时关机代码

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Button1: TButton;
Timer1: TTimer;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);

var

hToken : THandle;

Tkp : TTokenPrivileges;

Zero:DWORD;

begin

OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or

TOKEN_QUERY,hToken);

LookupPrivilegeValue(nil,'SeShutdownPrivilege',tkp.Privileges[0].Luid);

Tkp.PrivilegeCount :=1;

Tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;

AdjustTokenPrivileges(hToken,False,Tkp,SizeOf(TTokenPrivileges),nil,Zero);


end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
edit1.Text :=timetostr(time);
if (Edit2.Text = Edit1.Text ) then
begin
if RadioButton1.Checked then
begin

ExitWindowsEx(EWX_LOGOFF,0);

end; //注销

if RadioButton2.Checked then

begin

ExitWindowsEx(EWX_REBOOT,0);

end; //重启

if RadioButton3.Checked then

begin

ExitWindowsEx(EWX_SHUTDOWN or EWX_POWEROFF,0);

end; //关机


end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage('请检查您输入时间格式是否与当前时间格式相同');
form1.Hide;
end;

end.

相关主题
文本预览
相关文档 最新文档