2

已嘗試爲我的最新項目創建WiX安裝程序。我有一個奇怪的問題,如果我通過cmd提示符運行msi作爲管理它工作正常,自定義操作啓動沒有大驚小怪,一切正常,但如果我雙擊msi自定義操作不起作用,安裝程序失敗。我使用的Visual Studio 2012,並使用Windows 7WiX msi自定義操作未在Windows 7的有限權限下運行

<!--Custom Actions--> 
<Binary Id='customShortcut' SourceFile='$(var.CustomDir)\TestInstallerCustom.CA.dll'/> 
<Binary Id='customDir' SourceFile='$(var.CustomDir)\TestInstallerCustom.CA.dll'/> 
<Binary Id='removeDir' SourceFile='$(var.CustomDir)\TestInstallerCustom.CA.dll'/> 

<CustomAction Id='customShortcutId' BinaryKey='customShortcut' DllEntry='CustomShortcut' 
       Execute='immediate' Impersonate='no' Return='check' /> 
<CustomAction Id='customDirId' BinaryKey='customDir' DllEntry='CustomDir' 
       Execute='immediate' Impersonate='no' Return='check'/> 
<CustomAction Id='removeDirId' BinaryKey='removeDir' DllEntry='RemoveDir' 
       Execute='immediate' Impersonate='no' Return='check'/> 

<InstallExecuteSequence> 
    <Custom Action='customDirId' Before='InstallFinalize'/> 
    <Custom Action='customShortcutId' After='InstallFinalize'/> 
    <Custom Action="removeDirId" After="InstallValidate">REMOVE="ALL"</Custom> 
</InstallExecuteSequence> 

回答

3

'immediate'自定義操作不是由安裝高架部分執行。因此,它們只在安裝過程中被擡高(如你所見)。要提高自定義操作,它們必須是交易腳本的一部分。要做到這一點,請設置CustomAction元素Execute='deferred'屬性。

注意:推遲的自定義操作在MSI SDK中有其他限制:'Deferred Execution Custom Actions' topic。由於看起來自定義操作正在修改機器狀態,因此您還需要考慮添加回滾自定義操作以撤消由延遲自定義操作完成的更改。

編寫自定義操作很有挑戰性。這是自定義操作是安裝失敗最大的原因之一。如果您可以避免編寫自定義操作,我強烈建議您這樣做。 :)

+0

感謝您的答覆。網上有關於回滾自定義操作的信息嗎? – user2260125 2013-04-12 00:59:38

+0

可以在http://msdn.microsoft.com/en-us/library/windows/desktop/aa371369(v=vs.85).aspx標記爲「回滾自定義操作」的主題中 – 2013-04-12 03:00:22