首页 > Windows开发 > 详细

Delphi 重启应用程序(创建Bat文件的Process)

时间:2015-12-14 16:36:20      阅读:725      评论:0      收藏:0      [点我收藏+]

Delphi 重启应用程序
在工程主文件中加入
Delay(500);

//启动程序时请延时一段时间,否则只能重启一次
procedure RestartApp;
var
BatchFile: TextFile;
BatchFileName: string;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
begin
try
    BatchFileName := ExtractFilePath(ParamStr(0)) + _D.bat;
    AssignFile(BatchFile, BatchFileName);
    Rewrite(BatchFile);
    Writeln(BatchFile, ExtractFileName(Application.ExeName));
    Writeln(BatchFile, del   %0);
    CloseFile(BatchFile);
    FillChar(StartUpInfo, SizeOf(StartUpInfo), $00);
    StartUpInfo.dwFlags := STARTF_USESHOWWINDOW;
    StartUpInfo.wShowWindow := SW_HIDE;
    if CreateProcess(nil, PChar(BatchFileName), nil, nil,
      False, IDLE_PRIORITY_CLASS, nil, nil, StartUpInfo,
      ProcessInfo) then
    begin
      CloseHandle(ProcessInfo.hThread);
      CloseHandle(ProcessInfo.hProcess);
    end;
    Application.Terminate;
except
end;
end;

 

Delphi 重启应用程序(创建Bat文件的Process)

原文:http://www.cnblogs.com/findumars/p/5045127.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!