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

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

//启动程序时请延时一段时间,否则只能重启一次
procedure RestartApp;
var
BatchFile: TextFile;
BatchFileName: string;
ProcessInfo: TProcessInformation;
StartUpInfo: TStartupInfo;
begin
try
BatchFileName := ExtractFilePath(ParamStr()) + '_D.bat';
AssignFile(BatchFile, BatchFileName);
Rewrite(BatchFile);
Writeln(BatchFile, ExtractFileName(Application.ExeName));
Writeln(BatchFile, 'del %0');
CloseFile(BatchFile);
FillChar(StartUpInfo, SizeOf(StartUpInfo), $);
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;
上一篇:mysql外键设置选项


下一篇:C语言学习(记录)【内存相关_1:内存基础】