自动重试删除要用Inno Setup替换的文件

时间:2018-02-03 17:27:58

标签: inno-setup

我必须等待5-10秒,然后在我们的DBNetServices上单击重试以获取我们的PlazSales销售点软件。有没有办法让它自动等待至少一段时间?

错误:

  

尝试替换现有文件时发生错误:   DeleteFile失败;代码5;访问被拒绝。点击重试尝试   再次...

[Setup]
CloseApplications=yes   

[Files]
Source: {#AutoBackupNetwork}\DBNetService.exe; DestDir: {app}\server; \
    Flags: IgnoreVersion overwritereadonly

1 个答案:

答案 0 :(得分:1)

您可以实现用于删除文件的自定义逻辑,如:

[Files]
Source: {#AutoBackupNetwork}\DBNetService.exe; DestDir: {app}\server; \
    Flags: IgnoreVersion overwritereadonly; BeforeInstall: DeleteWithRetry
[Code]

procedure DeleteWithRetry;
var
  Path: string;
  Timeout: Integer;
  Step: Integer;
begin
  Path := ExpandConstant('{app}\server\DBNetService.exe');
  if FileExists(Path) then
  begin
    Log(Format('%s exists, will try to delete', [Path]));
    Timeout := 5000;
    Step := 100;
    while (Timeout > 0) and (not DeleteFile(Path)) do
    begin
      Log(Format('Failed to delete %s, will try again in %d ms', [Path, Step]));
      Sleep(Step);
      Timeout := Timeout - Step;
    end;
  end;
end;