delphi如何自动重启程序


本文整理自网络,侵删。

 思路1:
需要重启程序的时候,在onclose事件里面调用了一个批处理bat文件(AT 脚本);
然后在批处理文件里面加入适当延迟(比如2秒);通过批处理文件重新启动该程序;

思路2:
你另外写个小程序,用那个程序来启动你的程序

你的程序关闭时-》调用那个小程序
小程序启动你的程序(先判断程序是否已经关闭)
小程序自己关闭

在onclose里面
shellexecute(self.handle,nil,PChar('c:\小程序.exe'),nil,nil,sw_shownormal);

小程序的代码
在formcreate里面
shellexecute(self.handle,nil,PChar('c:\你的程序.exe'),nil,nil,sw_shownormal);
close;

思路3:
在退出前调用打开程序的语句,最简单

Application.Terminate;
winexec(Pchar(paramstr(0)), sw_show);

做成函数:
procedure KillApplication(Restart: boolean);
var
StartInfo: TStartupInfo;
ProcInfo: TProcessInformation;
begin
if Restart then
begin
GetStartupInfo(StartInfo);
FillChar(ProcInfo, SizeOf(TProcessInformation), #0);
CreateProcess(nil, GetCommandLine, nil, nil, False,
CREATE_NEW_PROCESS_GROUP + NORMAL_PRIORITY_CLASS, nil,
PChar(StartDir), StartInfo, ProcInfo);
end;
TerminateProcess(GetCurrentProcess, 1);

相关阅读 >>

Delphi 动态设置屏幕分辨率

Delphi 代替pos的函数

Delphi 7中ado控件打开access数据库文件

Delphi 一个call应该如何写?

Delphi2010安装twordapplication控件

tstringlist 常用操作

Delphi getdrivetypea() 查看驱动器类型

Delphi api: setwindowpos改变窗口的位置与状态

Delphi 根据文件路径获取文件名

Delphi webbrowser.oleobject属性

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...