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?
With such requirement, you cannot use the built-in AppMutex
directive.
You have to implement the mutex check yourself using CheckForMutexes
function in a loop, as you have been suggested to in your previous question:
[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;