2013-08-23 77 views

回答

4

在片段或產品元素下使用時,WiX Condition元素表示LaunchCondition Table中的條目,並由LaunchConditions Action處理。您看到的行爲是該基礎功能的限制。

這裏有一個博客文章中,我7年前寫的:

Short Comings of LaunchConditions

可悲的是,微軟從來沒有采取改善我的建議。因此,不必使用Condition元素,您必須編寫自己的自定義表和自定義操作來執行處理。

我在InstallScript和C#中有這樣的示例代碼,但我從來沒有用C/C++編寫過。

以下是InstallScript中的一個簡化示例。將它作爲僞代碼在C/C++中重構。您還需要創建SQL查詢使用的自定義表,定義和計劃自定義操作(我通常會在FindRelatedProducts之後安排它),並創建用於顯示錯誤文本的自定義對話框。所有這些都是未包含的WiX XML。

hDatabase = MsiGetActiveDatabase(hMSI); 
MsiDatabaseOpenView(hDatabase, "SELECT `Condition`, `Description` FROM `CustomLaunchConditions` ORDER BY `Ordering`", hView); 
MsiViewExecute(hView, 0); 

if(MsiViewFetch(hView, hRecord) == ERROR_SUCCESS) then 
    loop = TRUE; 
    while(loop) 
    nvBufferSize = MAX_STRING; 
    MsiRecordGetString(hRecord, 1, svProperty, nvBufferSize); 

    if(!MsiEvaluateCondition(hMSI, svProperty)) then 
     nvBufferSize = MAX_STRING; 
     MsiRecordGetString(hRecord, 2, svValue, nvBufferSize); 
     hFormatRecord = MsiCreateRecord(1); 
     MsiRecordSetString(hFormatRecord, 0, svValue); 
     nvBufferSize = MAX_STRING; 
     MsiFormatRecord(hMSI, hFormatRecord, svResult, nvBufferSize); 
     svWarningMessage = svWarningMessage + svResult + "\r\n"; 
    endif; 

    if(MsiViewFetch(hView, hRecord) != ERROR_SUCCESS) then 
     loop = FALSE; 
    endif; 
    endwhile; 
    MsiSetProperty(hMSI, "CustomLaunchConditionsText", svWarningMessage); 
endif; 
+0

Christpher感謝您的回答。你有沒有可能分享你提到的這段代碼?這對我很有幫助。 –

+0

答覆已更新。 –