Our product allows updates to be installed via an MSI installer. An update consists of several files which need to be copied to disk, and the addition of database entries which the installer adds by running several SQL scripts.
Updates can be (and commonly are) installed while the main executable is open. Because of this, I need a way of preventing access to a certain database-intensive feature while the upgrade is in progress.
My current thoughts:
- Installer adds a registry key when it starts up.
- Update is installed.
- On success or failure, the registry key is deleted.
Meanwhile, the application (written in C#) queries for the presence of the registry key, displaying an error dialog if it is set.
Is this reliable? I’m concerned about what happens if the user kills the installer via task manager, then the registry key will never be deleted and the user will be permanently locked out of the feature. Also not sure about any race conditions that the above solution could lead to.
Any suggestions about whether this approach is feasible, or a better approach?
Windows Installer already implements a Mutex to indicate that an installation is in progress. Just code your database intensive code to check for that mutex and no-op while it’s present. Nothing additional needs to be done.
(Note: using this will stop your processing any time MSI is installing a product which is probably not a bad idea anyways. If you want a unique mutex, it’s trivial to write a custom action. )
_MSIExecute Mutex
Update by @LeopardSkinPillBoxHat
The above answer did what I needed. This is the code I ended up using: