delphi编写定时关机问题

来源:百度知道 编辑:UC知道 时间:2024/06/02 15:47:24
初学delphi、想编个定时关机的程序、
一个edit编辑框、一个button按钮
想在编辑框里输入时间time,在时间time后电脑关机.
我想的程序:
procedure TForm1.Button1Click(Sender: TObject);
var
time:integer;
begin
time:=strtoint(edit1.text);
WinExec('shutdown -s -t time', SW_SHOW); //t秒后关机
end;
当然这程序错了、不过不知道错哪、请指教!
那(shutdown -s -t **,sw_show)里的**是什么数据类型?

你把time直接当作字符传进去当然错啦,按1楼的改,
winexec(pchar('cmd /c shutdown -s -f -t '+inttostr(time) ),sw_show);
你需要自己验证输入的时间格式,因为你输入的time是字符串转来的,最好是strtointdef设置一个默认值,数字就行
因为那个××是说关闭延时多少秒。即你输入的只要是数字,就是多少秒后关闭
,建议加上参数-f,强制关闭

winexec(pchar('cmd /c shutdown -s -t '+inttostr(time)),sw_show);

你这样关机在没有权限下的话是不能实现的吧,这个方法关机不好的