【发布时间】:2011-11-18 15:08:05
【问题描述】:
我们分发了旧版本的 wix 安装程序,其中一些文件安装为 Permanent="yes" 组件。但是现在我们想要求用户在 unistall 上保留或删除这些文件。此文件位于 Program Files 文件夹中。我们得到 DELETE_ALL 用户响应。这是:
<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:\Program Files (x86)\Company\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
或者如果我们从管理员 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 自定义操作设置 Impersonate (yes/no) 和 Execute (immediate/deferred) 的不同值,但没有成功。
进一步,我们尝试通过具有 RemoveFiles 的组件或用 c# 编写的 CustomAction 来执行此删除操作,该操作与我们使用的其他工具一样标有 CustomActionAttribute。也没有成功。
[CustomAction]
public static ActionResult DeleteAll(Session session) { /*...*/ }
或者从 CustomAction 调用另一个方法:
[PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")]
private static void DeleteFiles() { /*...*/ }
我们得到一个期望:
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)
是否可以实现一个功能来按需删除以前版本中安装的永久文件?有什么想法吗?
【问题讨论】:
标签: c# windows-7 wix custom-action