I am trying to use a custom action (written in native C++ code) to check whether my installer is already running at time of installation.
Code is :
#include <Windows.h>
#include <Msi.h>
#include <MsiQuery.h>
#include <tchar.h>
#pragma comment(linker, "/EXPORT:CheckMultipleInstances=_CheckMultipleInstances@4")
#pragma comment(lib, "msi.lib")
extern "C" UINT __stdcall CheckMultipleInstances(MSIHANDLE hInstall)
{
CreateMutexA(0, FALSE, "SIERRAINSTALL_MUTEX");
if (GetLastError() == ERROR_ALREADY_EXISTS)
MsiSetProperty (hInstall, "INSTALLRUNNING", "1");
return ERROR_SUCCESS;
}
The relevant WiX code is as follows:
<CustomAction Id='CheckOtherInstalls' BinaryKey='InstallCheck' DllEntry='CheckMultipleInstances'/>
<CustomAction Id='RefuseInstall' Error='Sierra Installer is already running.'/>
<Custom Action='CheckOtherInstalls' After='CostFinalize'/>
<Custom Action='RefuseInstall' After='CheckOtherInstalls'>INSTALLRUNNING = "1" AND NOT Installed</Custom>
The problem is, no matter when I schedule this custom action, it doesn't actually execute it until after the user has said "Install" on the installer.
I want this custom action to be executed when the installer launches, before the welcome screen is even displayed (if this is possible).
How can I accomplish this?
EDIT :: This is my solution (ish)
I ended up triggering my custom actions when the user clicks "Next" on the welcome dialog. No fiddling around with the installexecutesequence or installUisequence worked, and this ends up being a good middle ground for my purposes.
If anyone is interested, this is what I came up with:
<UI Id='MyWixUI_Mondo'>
<UIRef Id='WixUI_Mondo'/>
<Publish Dialog='WelcomeDlg' Control='Next' Event="DoAction" Value="CheckOtherInstalls">1</Publish>
<Publish Dialog='WelcomeDlg' Control='Next' Event="DoAction" Value="RefuseInstall">INSTALLRUNNING = "1"</Publish>