You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Wix安装器升级时保留服务‘登录身份’配置的问题求助

解决WixToolset服务升级时丢失登录身份配置的问题

问题核心

使用WixToolset.Sdk 5.0.2制作服务安装包,执行MajorUpgrade时,安装器会卸载并重新安装服务,导致用户后续修改的「登录身份」等配置丢失。尝试将<ServiceInstall>分离到带NOT Installed条件的组件后,首次安装也无法正常安装服务。

修改后失败的原因

把<ServiceInstall>放到独立组件但未设置KeyPath,Windows Installer要求每个组件必须有KeyPath(文件、注册表项等)才能识别该组件是否需要安装/执行。没有KeyPath的组件,即使Condition="NOT Installed"满足,也不会触发<ServiceInstall>的安装动作。

正确解决方案

方案1:给ServiceInstall组件添加KeyPath(适合需要隔离服务安装逻辑的场景)

给包含<ServiceInstall>的组件添加一个注册表项或空文件作为KeyPath,确保首次安装时组件被正确执行,升级时因条件跳过服务安装:

<Component Id="InstallService" Guid="DE13861C-EED7-481E-8AD1-D2057D4D8BAE" Condition="NOT Installed">
  <!-- 添加注册表项作为KeyPath -->
  <RegistryKey Root="HKLM" Key="Software\MyCompany\MyService" Action="createAndRemoveOnUninstall">
    <RegistryValue Name="ServiceInstalled" Type="integer" Value="1" KeyPath="yes" />
  </RegistryKey>
  <ServiceInstall Id="ServiceInstaller" Type="ownProcess" Name="My Service" DisplayName="My Service" Description="My Description" Start="auto" ErrorControl="critical" />
</Component>
<Component Id="MainExecutable" Guid="CE13861C-EED7-481E-8AD1-D2057D4D8BAE">
  <File Id="MyService.exe" Name="MyService.exe" Source="C:\out\MyService.exe" KeyPath="yes" />
  <ServiceControl Id="ServiceUnInstaller" Name="My Service" Remove="uninstall" Stop="uninstall" Start="install" Wait="yes" />
</Component>

方案2:给ServiceInstall添加Reinstall="no"属性(更简洁的方案)

无需分离组件,直接给<ServiceInstall>添加Reinstall="no",告诉Windows Installer升级时不要重新安装服务,从而保留用户修改的配置:

<Component Id="MainExecutable" Guid="CE13861C-EED7-481E-8AD1-D2057D4D8BAE">
  <File Id="MyService.exe" Name="MyService.exe" Source="C:\out\MyService.exe" KeyPath="yes" />
  <!-- 添加Reinstall="no",升级时不重新安装服务 -->
  <ServiceInstall Id="ServiceInstaller" Type="ownProcess" Name="My Service" DisplayName="My Service" Description="My Description" Start="auto" ErrorControl="critical" Reinstall="no" />
  <ServiceControl Id="ServiceUnInstaller" Name="My Service" Remove="uninstall" Stop="uninstall" Start="install" Wait="yes" />
</Component>

说明

  • 方案2的Reinstall="no"会阻止Windows Installer在升级时重新应用ServiceInstall的配置,从而保留用户后续修改的登录身份、启动类型等设置。
  • 方案1通过隔离服务安装组件,确保仅首次安装时执行服务注册,升级时跳过,适合需要更精细控制服务安装时机的场景。

内容的提问来源于stack exchange,提问作者Ne0

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 22:46:05