I wouldn’t call it expected, but for me, it’s unsurprising. I have never had any luck getting the installer to terminate the app. My solution is using a mutex to make sure the two cannot run at the same time. But this comes with some hoops to jump through. So I’ll point you to my script and guide you as best as I can. Beacon/Setup.iss at master · thommcgrath/Beacon · GitHub
The important keys are AppMutex and SetupMutex in the [Setup] section. The installer will check the status of AppMutex and will not continue if something is already holding the mutex. SetupMutex is similar, but the installer holds this mutex, and does not care if something else is already holding it. So you need both to allow your app and your installer to check on each other.
You’ll also need to use WindowsMutexMBS instead of Xojo’s Mutex class, because Xojo’s mutex only appears compatible with other Xojo apps. I’m not sure the technical reasons for this, but I do know Xojo’s built-in mutex won’t work as-is.
When your app is opening, check the setup mutex:
Var SetupMutex As New WindowsMutexMBS
SetupMutex.Create("com.my.app.installer")
If SetupMutex.Lasterror <> 0 Or SetupMutex.TryLock = False Then
MessageBox("The installer is running")
Quit
Return
End If
It is not necessary to retain the SetupMutex object. Next, get your app’s mutex
Static AppMutex As New WindowsMutexMBS
AppMutex.Create("com.my.app")
If AppMutex.LastError <> 0 Or AppMutex.TryLock = False Then
MessageBox("Another instance is running")
Quit
Return
End If
If you already have mutex logic of your app, just adapt it to use the WindowsMutexMBS class instead. Also make sure to release the mutex when your app is closing, though this will happen automatically. It’s just good housekeeping.
Done? Well… kind of. Technically, this will work. Practically, your SetupMutex check will fail if your installer launches your app after the install finishes. That’s less than ideal. But there’s a solution to that too.
In my setup script (line 127 at the time of this writing) is
Filename: "{app}\{#MyAppExeName}"; Parameters: "/NOSETUPCHECK"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Check: not CmdLineParamExists('/NOLAUNCH'); Flags: nowait postinstall
The meat you’re looking for here is Parameters: "/NOSETUPCHECK". This will get passed to the app, so you’ll need to detect it and not check your SetupMutex;
Var CommandLine As String = System.CommandLine
Var SkipSetupCheck As Boolean = CommandLine.EndsWith("/NOSETUPCHECK") Or CommandLine.IndexOf(" /NOSETUPCHECK ") > -1
If SkipSetupCheck = False Then
Var SetupMutex As New WindowsMutexMBS
SetupMutex.Create("com.my.app.installer")
If SetupMutex.Lasterror <> 0 Or SetupMutex.TryLock = False Then
MessageBox("The installer is running")
Quit
Return
End If
End If
And of course, wrap all this Xojo code in #if TargetWindows as needed.