我們已經發布了一箇舊版本的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)
這是可能實現一個功能刪除安裝在永久文件以前版本的需求?任何想法?
我們測試了它,正如我在問題中所述,沒有成功。不管怎樣,謝謝你。 – msierra