注册 登录
编程论坛 Delphi论坛

定时打开某个程序

s912360101 发布于 2009-09-28 14:50, 1542 次点击
各位大哥,小弟打算给朋友写个指定时间(比如晚上8点55)启动某个程序的小程序。执行程序方面我使用的是Shellexecute,在时间上不知道怎么样实现,
是不是,先得到系统时间,然后在与自己给定的时间作比较,如果相同,就执行。还有一点就是,希望运行时的时候没有窗体。谢谢。。
8 回复
#2
s9123601012009-09-28 14:53
这行代码是不是就没有用了呢 Timer1.Enabled:= True;  不是没有窗体吗,那么这行代码就可以省了吧!?
#3
mohao1632009-09-28 15:52
调用Shellexecute不用窗体么?写成console应用程序也要一直打开你写的程序才行吧,这样Timer的Enabled应该也要激活的,可以定义一个函数获取当前时间,不过没在console应用程序下用过
#4
s9123601012009-09-28 21:50
能不能贴出源码来呢
#5
mohao1632009-09-29 11:16
你要实现的功能其实很简单
先这样,定一个Button,一个edit,一个Timer

一开始Timer的Enabled设置为FALSE

procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
   if edit1.text = TimeToStr(Time) then
   begin
     shellexecute(handle,'open','D:\Close LCD.exe',nil,nil,SW_SHOW);
     close();
   end;
end;



其实要设置的复杂一点就对edit设置只能输入标准格式时间
单击Button1后执行功能并隐藏当前窗体
把界面和功能做得更完美
#6
s9123601012009-09-30 13:02

谢谢了啊。我把问题想复杂了。。
#7
d5d4hf2009-10-10 09:50
厉害学历了
#8
xyouzhou2009-11-02 22:32
shellexecute(handle,'open','D:\Close LCD.exe',nil,nil,SW_SHOW);
这句老是报错  怎么回事
错误信息如下:
[Error] Unit1.pas(41): Undeclared identifier: 'shellexecute'
[Error] Unit1.pas(46): ';' expected but '.' found
[Error] Unit1.pas(48): Declaration expected but end of file found
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'


[ 本帖最后由 xyouzhou 于 2009-11-2 22:35 编辑 ]
#9
s9123601012010-01-19 20:09
你在unit 上些Shellapi 了没有哦。
1