我正嘗試使用自定義操作(使用本機C++代碼編寫)來檢查安裝程序是否已在運行。WiX:使用自定義操作檢查當前正在運行的安裝
代碼是:
#include <Windows.h>
#include <Msi.h>
#include <MsiQuery.h>
#include <tchar.h>
#pragma comment(linker, "/EXPORT:[email protected]")
#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;
}
相關的WiX代碼如下:
<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>
的問題是,無論什麼時候我安排這個自定義操作,它實際上並沒有執行,直到用戶在安裝程序上說「安裝」後。
我希望在安裝程序啓動時甚至在顯示歡迎屏幕之前執行此自定義操作(如果可以的話)。
我該如何做到這一點?
編輯::這是我的解決方案(ISH)
我結束了我的觸發自定義操作,當用戶點擊「下一步」,在歡迎對話框。沒有擺弄installexecutesequence或installUsequence的工作,這最終成爲我的目的一個很好的中間地帶。
如果有人有興趣,這是我想出了:
你想解決什麼問題? Windows Installer確保一次只運行一個安裝 - 即關鍵部分,即。 –
_MSIExecute Mutex:http://msdn.microsoft.com/en-us/library/windows/desktop/aa372909(v=vs.85).aspx –