AppMutex with Inno Setup: Wait few seconds before prompt

安稳与你 提交于 2019-12-04 02:40:24

问题


Using Inno Setup together with an AppMutex works fine - when the setup is started and the mutex still exits, the user is prompted to close this application.

But following question: Is there a way to tell Inno Setup to wait 2-3 seconds if the program closes itself before showing the user this prompt?

The reason is that I'm running the Inno Setup from the program itself for auto-update purpose. Directly after the setup file is executed the program closes itself, but obviously that takes too long (at least on some systems). So Inno Setup shows this - in this case - useless dialog to the user although the program is closing itself already.

Therefore I would like to accomplish that Inno Setup waits 2-3 seconds and only if the mutex still exists after that time it should show the prompt to the user.

Is there a way to accomplish this?


回答1:


With such requirement, you cannot use the built-in AppMutex directive.

You have to implement the mutex check yourself using 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;


来源:https://stackoverflow.com/questions/35081681/appmutex-with-inno-setup-wait-few-seconds-before-prompt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!