Wix安装程序-从“控制面板”中的“卸载”或“更改程序”运行时,如何以管理特权运行更改 [英] Wix installer - how to run change with administrative privileges when run from Uninstall or change program in Control Panel

查看:116
本文介绍了Wix安装程序-从“控制面板”中的“卸载”或“更改程序”运行时,如何以管理特权运行更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的安装程序有一个自定义操作,该操作与Windows服务联系并设置一些参数。
为了成功使用该服务,必须以提升的特权运行该服务。

My installer has a custom action which contacts a windows service and set some parameters. In order to successfully use the service, it must be run with the elevated privileges.

在首次安装时,当用户单击安装按钮时,随UAC提示出现,并成功完成安装。但是,当用户决定更改产品(添加新功能)时,对该服务的调用将失败!发生这种情况是因为安装程序未在特权模式下运行。当我从具有管理权限的命令提示符启动安装程序时,更改操作也成功完成。

In the first time install when a user clicks on the Install button, it is presented with the UAC prompt and install completes successfully. However, when a user decides to change the product(add new feature), call to the service will fail! This happens because installer is not run in the privileged mode. When I start the installer from a command prompt with administrative rights, change operation also completes successfully.

我遇到了以下文章建议创建一个引导程序。有没有更简单的方法可以做到这一点?

I've came across the following article which suggests creating a bootstrapper. Is there any easier way to accomplish this?

我是否正确实施了自定义操作?这是自定义操作代码

Did I implement the custom action correctly?. Here's the custom action code

     <CustomAction Id='SetParams' BinaryKey='Setup.CustomAction' DllEntry='SetParameters' Execute='deferred' Impersonate='no' Return='asyncWait'/>
<Binary Id='Setup.CustomAction' SourceFile='$(var.CustomActionDll)' />

<InstallExecuteSequence>
  <Custom Action='SetParams' Before='InstallFinalize'><![CDATA[REMOVE <> "ALL"]]></Custom>
</InstallExecuteSequence>

更新:在Cosmin发表评论后,我意识到我正在访问CA中的会话数据。 SetParams CA使用在UI序列中生成的动态属性。为了访问延迟CA中的数据,我创建了一个即时CA,该CA动态提取此数据并将其放入CustomActionData中。

Update: After Cosmin's comment, I realized I was accessing the session data in CA. SetParams CA uses dynamic properties generated in the UI sequence. To access data in deferred CA, I've created an immediate CA which dynamically extracts this data and puts it in the CustomActionData.

<CustomAction Id='SaveParams' BinaryKey='Setup.CustomAction' DllEntry='SaveParameters' Execute='immediate'  Return='check'/>
<CustomAction Id='SetParams' BinaryKey='Setup.CustomAction' DllEntry='SetParameters' Execute='deferred' Impersonate='no' Return='check' />

<Custom Action='SaveParams' Before='SetParams'><![CDATA[REMOVE <> "ALL"]]></Custom>
  <Custom Action='SetParams' Before='InstallFinalize'><![CDATA[REMOVE <> "ALL"]]></Custom>

以下是自定义操作中SaveParameters方法的一部分

Following is the part of SaveParameters method in the custom action

propertyName = moduleInfo.GetPropertyName(moduleParameter.Name);
customActionData.Append(string.Format(CultureInfo.InvariantCulture, "{0}={1};", propertyName, session[propertyName]));

此方法有效!
从admin cmd会话启动时,[propertyName]返回正确的值,但是当我从非高架cmd提示符运行安装程序更改时,我无法访问直接CA中的属性值-session [propertyName]返回空字符串?!

This approach works! When started from admin cmd session[propertyName] returns the correct value, but when I run the installer change from non-elevated cmd prompt, I cannot access the property values in the immediate CA - session[propertyName] returns empty string ?!

我可以访问wxs文件中定义的(静态)属性

I can access the (static) property defined in wxs file

<Property Id="INSTALL" Secure="yes" /> 

但不是我在UI序列中的其他一些直接自定义操作中添加的对象,例如

but not the one's I've added in some other immediate custom action in the UI sequence like this

session[property] = parameters[paramcount++];


推荐答案

未设置模拟属性的延迟自定义操作将确保

Deferred custom action with no impersonation attribute set will ensure that the CA is run in elevated mode.

我添加了一个新的,以解决出现的另一个问题。

I've added a new question to address the other issue which emerged.

访问的解决方案动态属性值问题

Solution to accessing dynamic property value issue


  1. 立即执行的操作,该操作读取要从执行
    序列移至UI序列的属性

  2. 执行阶段中的动作可以从问题中所述的安全属性访问数据
    。如果属性
    是在CA中动态创建的,则必须将它们添加到
    SecureCustomProperties系统属性中。分隔符char是‘;’。

这篇关于Wix安装程序-从“控制面板”中的“卸载”或“更改程序”运行时,如何以管理特权运行更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆