2011-11-18 22 views
1

我們已經發布了一箇舊版本的wix安裝程序,其中一些文件安裝爲Permanent =「yes」組件。但是現在我們想要求用戶保留或刪除這些文件。這些文件位於Program Files文件夾中。我們獲得DELETE_ALL用戶響應。這就是:WIX:在Windows 7的程序文件下使用自定義操作刪除永久文件?

<InstallExecuteSequence> 
     <!-- more custom actions --> 
     <Custom Action="DeleteFiles" Before="InstallFinalize">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL") AND (NOT (DELETE_ALL=0))</Custom> 
</InstallExecuteSequence> 
<CustomAction Id="DeleteFiles" ExeCommand='Company.CustomActions.ExeActions.exe' Directory="INSTALLDIR" Return="check" Impersonate="yes" Execute="immediate" /> 

Company.CustomActions.ExeActions.exe比刪除基於C這些文件一個簡單的控制檯應用程序:\程序文件(x86)\企業\ PROGRAM1一個清單與

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> 

上的.msi執行,我們得到這樣的行:

MSI (s) (20:88) [15:16:19:130]: MSI_LUA: Elevation required to install product, will prompt for credentials 
MSI (s) (20:88) [15:16:21:798]: MSI_LUA: Credential Request return = 0x0 
MSI (s) (20:88) [15:16:21:798]: MSI_LUA: Elevated credential consent provided. Install will run elevated 

或者,如果我們從海軍上將推出來inistrator CMD.EXE:

MSI (c) (24:F8) [12:35:32:530]: MSI_LUA: Setting AdminUser property to 1 because this is the client or the user has already permitted elevation 

我們試圖爲我們的DeleteFiles自定義操作設置diferent值設置爲假冒(是/否)和執行(即時/延遲),而得到它的成功。

此外,我們嘗試使用RemoveFiles或CustomAction在C#中編寫一個CustomAction屬性標記爲CustomActionAttribute的組件來執行此刪除操作。也沒有成功。

[CustomAction] 
    public static ActionResult DeleteAll(Session session) { /*...*/ } 

或致電從CustomAction到另一種方法:

[PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")] 
private static void DeleteFiles() { /*...*/ } 

我們得到一個expcetion:

Request for principal permission failed. 
at System.Security.Permissions.PrincipalPermission.ThrowSecurityException() 
at System.Security.Permissions.PrincipalPermission.Demand() 
at System.Security.PermissionSet.DemandNonCAS() 
at Company.CustomActions.DeleteFiles(Session session) 
at Company.CustomActions.DeleteALL(Session session) 

這是可能實現一個功能刪除安裝在永久文件以前版本的需求?任何想法?

回答

0

最後我們使用WixShellExec從我們之前一直使用二進制WixCA執行(以時間,而不是在執行)啓動特權應用程序,在計劃每個WixShellExec cutom操作之前設置WixShellExecTarget的值。

真正的問題是,這種方式不允許檢索自定義操作上的實際錯誤(不是WixShellExec調用中的錯誤,而是底層的錯誤)。現在對我們來說是一個有效的場景。所以我們這樣解決了它。

實施例:

<InstallExecuteSequence> 
    <!-- more custom actions --> 
    <Custom Action="SetLaunchDeleteAll" Before="InstallFinalize">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL") AND (NOT (DELETE_ALL=0))</Custom> 
    <Custom Action="DeleteFiles" Before="InstallFinalize">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL") AND (NOT (DELETE_ALL=0))</Custom> 
</InstallExecuteSequence> 
<InstallUISequence> 
<!-- more custom actions --> 
    <Custom Action="SetLaunchProperty" Sequence="9990">CUSTOM_CONDITIONS</Custom> 
</InstallUISequence> 
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Execute="immediate" Impersonate="yes" Return="check" /> 
<!-- more custom actions --> 
<CustomAction Id="DeleteFiles" BinaryKey="WixCA" DllEntry="WixShellExec" Execute="immediate" Impersonate="yes" Return="check" /> 
<CustomAction Id="SetLaunchProperty" Property="WixShellExecTarget" Value="[#Company.Program.exe]" /> 
<CustomAction Id="SetLaunchDeleteAll" Property="WixShellExecTarget" Value="[#Company.CustomActions.ExeActions.exe]" /> 
<UI> 
    <Publish Dialog="MyExitDialog" Control="Finish" Order="1" Event="DoAction" Value="LaunchApplication">CUSTOM_CONDITIONS</Publish> 
</UI> 
<Property Id="WixShellExecTarget" Value="[#Company.CustomActions.ExeActions.exe]"/> 

而且DeleteAll()方法不與PrincipalPermissionAttribute裝飾,雖然Company.CustomActions.ExeActions.exe清單確實需要管理員權限(requestedExecutionLevel requireAdministrator)。

對於這些操作,卸載並要求刪除顯示兩次使用本地Windows配置的UAC(一次用於卸載,另一次用於這些自定義操作)。

1

你應該設置自定義動作來爲推遲沒有模擬

<CustomAction Id="DeleteFiles" ExeCommand='Company.CustomActions.ExeActions.exe' Directory="INSTALLDIR" Return="check" Impersonate="no" Execute="deferred" /> 
+0

我們測試了它,正如我在問題中所述,沒有成功。不管怎樣,謝謝你。 – msierra

相關問題