使用 Windows 服务更新包会重置服务的帐户和密码 [英] Updating a package with a Windows Service resets service's account and password

查看:25
本文介绍了使用 Windows 服务更新包会重置服务的帐户和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WiX 开发 MSI 安装程序.我正在努力使开发尽可能简单:这是一个内部产品,我的用户是我们的 IT 人员.

该产品包含一项 Windows 服务,必须将其配置为在每台计算机的不同帐户下运行.

我为我的用户(首次安装)计划的工作流程如下:

  1. 运行安装程序(安装程序在默认帐户下设置服务)
  2. 通过 sc 或本地服务小程序停止服务
  3. 更新服务属性以在正确的机器特定帐户下运行.(每台机器的帐户都不一样,只有 IT 人员可以访问密码.)
  4. 重启服务

后续更新将包括从更新的 MSI 文件安装.

在测试小"更新时,我惊讶地发现安装程序将服务重置为在默认帐户下运行.这对我来说是一个主要问题,因为它让我的用户很难更新他们的服务器.每次有更新时,他们都必须在每台机器上重新输入帐户信息.我预计这会发生在主要"更新上,但不会发生在小"更新上.

  1. 有没有办法配置安装程序,使其在小"或小"更新期间不会更改服务的现有帐户/密码配置?>

  2. 在维修"期间也会发生这种情况吗(我没试过)?

这是我的组件在 .wxs 文件中的样子:

<File Id="filService" KeyPath="yes" Name="ServiceApp.exe"/><ServiceInstall Id="ServiceInstall" Name="ServiceApp" DisplayName="我的服务"Type="ownProcess" Start="auto" ErrorControl="normal"帐户="本地系统"><util:PermissionEx ...这里的属性.../></ServiceInstall><ServiceControl Id="StartService" Start="install" Stop="both" Remove="卸载"Name="ServiceApp" Wait="yes"/></组件>

我原以为 Remove="uninstall" 会在没有更改的情况下保留该服务.显然不是.(如果这种情况发生在重大"更新上,我并不太担心).

我还注意到 ServiceConfig 元素具有似乎符合要求的属性 (OnReinstall),但根据蜡烛错误消息,很明显 OnReinstall 旨在仅影响元素的配置成员(PreShutdownDelay 等),而不影响整个服务安装.

我已经研究了这些:

奇怪的是,这个答案表明这只是主要"升级的问题.那不是我的经历.我的经历是侥幸吗?

在安装过程中提示输入帐户和密码本来可以,但在这种情况下将密码存储在注册表或其他地方并不是一个真正的选择,并且每次更新时都必须重新输入凭据与必须手动重新配置服务.

解决方案

最终对我有用的是

 </DeleteServices><安装服务><![CDATA[未安装]]></安装服务>

我通过一系列反复试验以及其他一些具有类似答案的线程的组合得出了这个答案.

为什么 only 不起作用的可能原因之一是因为 WIX 还会在重新安装时删除该服务.我们只想在初始安装期间安装该服务一次.我们还希望确保在卸载时删除该服务.这是唯一对我有用的条件组合,允许服务保留其设置和用户帐户.

I'm working on an MSI installer with WiX. I'm trying to keep this as simple to develop as possible: this is an internal product, and my users are our IT personnel.

The product includes a Windows Service that must be configured to run under a different account for each machine.

The workflow I was planning for my users (for first-time install) is as follows:

  1. Run the installer (The installer sets up the service under a default account)
  2. Stop the service via sc or Local Services applet
  3. Update the service properties to run under the correct machine-specific account. (The account is different for each machine, and only the IT personnel has access to the passwords.)
  4. Restart the service

Subsequent updates would consist of installing from updated MSI files.

Testing a "small" update, I was surprised to find that the installer reset the service back to running under the default account. This is a major problem for me because it makes it really hard for my users to update their servers. They would have to re-enter the account information on each machine every time there is an update. I expected that would happen with a "major" update, but not on a "small" one.

  1. Is there a way to configure the installer so that it does not change the existing account/password configuration for a service during a "small" or a "minor" update?

  2. Will this happen during a "repair" as well (I haven't tried that)?

Here's what my component looks like in the .wxs file:

<Component Id="cmpService" Guid="{MYGUIDHERE}">
  <File Id="filService" KeyPath="yes" Name="ServiceApp.exe" />
  <ServiceInstall Id="ServiceInstall" Name="ServiceApp" DisplayName="My Service"
                  Type="ownProcess" Start="auto" ErrorControl="normal"
                  Account="LocalSystem">
    <util:PermissionEx ... attributes here... />
  </ServiceInstall>
  <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall"
                  Name="ServiceApp" Wait="yes" />
</Component>

I had expected that Remove="uninstall" would preserve the service in place if there were no changes to it. Apparently not. (I'm not too worried if this happens on "major" updates).

I also noticed that the ServiceConfig element has attributes (OnReinstall) that seem to fit the bill, but based on candle error messages, it's pretty clear that OnReinstall is intended to affect only the configuration members of the element (PreShutdownDelay, etc.) rather than the service installation as a whole.

I've looked into these:

Curiously, this answer suggests that this is an issue only for "major" upgrades. That wasn't my experience. Was my experience a fluke?

It would have been OK prompting for an account and password during installation, but storing the password in the registry or elsewhere is a not really an option in this case, and having to reenter the credentials on every update is just as disruptive as having to reconfigure the service by hand.

解决方案

What finally ended up working for me was

  <DeleteServices><![CDATA[REMOVE ~= "ALL" AND (NOT UPGRADINGPRODUCTCODE)]]> </DeleteServices>
  <InstallServices><![CDATA[NOT Installed]]> </InstallServices>

I arrived at this answer through a series of trial and error attempts and a combination of a few other threads with similar answers.

One of the possible reasons why only the doesn't work is because WIX also removes the service upon re-install.. we only want to install the service once, during the initial install. We also want to make sure that the service is removed upon uninstall. This is the only combination of conditions which worked for me, allowing the service to keep its settings and user account.

这篇关于使用 Windows 服务更新包会重置服务的帐户和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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