我以前写的关机程序,参考下吧
procedure Tformshutdown.xpButton1Click(Sender: TObject);
begin
DateTimePicker1.visible:=true;
if application.MessageBox('你是否决定执行本操作?','系统询问',
mb_okcancel+mb_ok)=idok then
begin
if (radiobutton1.Checked) then
shutdownsystem(ewx_shutdown)
else if (radiobutton2.Checked) then
shutdownsystem(ewx_reboot)
else if (radiobutton3.checked) then
shutdownsystem(ewx_logoff)
else if (radiobutton4.Checked) then
begin
showmessage('请在文本框设定关机时间,并确保本窗体运行中');
datetimepicker1.time:=time;
//shutdownsystem(ewx_shutdown);
end
else if (radiobutton5.Checked) then
shutdownsystem(ewx_poweroff);
end;
end;
procedure Tformshutdown.Timer1Timer(Sender: TObject);
begin
if timetostr(stime)>timetostr(time) then
radiogroup1.Caption:='离关机还有:'+timetostr(stime-time)
else
begin
radiogroup1.Color:=clred;
radiogroup1.Font.Size:=20;
i:=i-1;
radiogroup1.Caption:=('十秒关机倒记时:'+inttostr(i));
if i=0 then
shutdownsystem(ewx_shutdown);
end;
if timetostr(encodetime(0,00,10,00))=timetostr(stime-time) then
able:=true;
//rtime:=timetostr(time);
//if comparestr(rtime,ltime)=0 then 比较2字符是否相等
if able=true then
begin
radiogroup1.Color:=clred;
radiogroup1.Font.Size:=20;
i:=i-1;
radiogroup1.Caption:=('十秒关机倒记时:'+inttostr(i));
if i=0 then
shutdownsystem(ewx_poweroff);
end;
//shutdownsystem(ewx_shutdown);
end;
//else
//showmessage('请正确设定时间')
procedure Tformshutdown.DateTimePicker1Change(Sender: TObject);
begin
ltime:=timetostr(datetimepicker1.time);
stime:=datetimepicker1.time;
timer1.Enabled:=true;
end;
procedure Tformshutdown.FormCreate(Sender: TObject);
begin
able:=false;
i:=10;
end;
end.