带有 Inno Setup 的 AppMutex:在出现提示之前等待几秒钟

AppMutex with Inno Setup: Wait few seconds before prompt

将 Inno Setup 与 AppMutex 一起使用效果很好 - 当安装程序启动并且互斥体仍然存在时,系统会提示用户关闭此应用程序。

但是下面的问题: 如果程序在向用户显示此提示之前自行关闭,是否有办法告诉 Inno Setup 等待 2-3 秒?

原因是我 运行 程序本身的 Inno 安装程序用于自动更新目的。安装文件执行后,程序会立即自行关闭,但显然这需要很长时间(至少在某些系统上)。因此 Inno Setup 向用户显示了这个 - 在这种情况下 - 无用的对话框,尽管程序已经自行关闭。

因此,我想完成 Inno Setup 等待 2-3 秒,并且只有在该时间之后互斥锁仍然存在的情况下,它才应该向用户显示提示。

有没有办法做到这一点?

有这样的要求,你不能使用内置的AppMutex directive

您必须使用 CheckForMutexes function:

自行实施互斥检查
[Code]

const
  MutexName = 'MutexName';

function InitializeSetup: Boolean;
var
  WaitInterval: Integer;
  Wait: Integer;
begin
  Wait := 3000;

  WaitInterval := 250;
  while (Wait > 0) and CheckForMutexes(MutexName) do
  begin
    Log('Application is still running, waiting');
    Sleep(WaitInterval);
    Wait := Wait - WaitInterval;
  end;

  while CheckForMutexes(MutexName) do
  begin
    if MsgBox(
         FmtMessage(SetupMessage(msgSetupAppRunningError), ['MyApplication']),
         mbError, MB_OKCANCEL) <> IDOK then
    begin
      Abort;
    end;
  end;

  Result := True;
end;