Wix:使用用户指定的服务名称安装Windows服务

Rom*_*zyk 2 windows service installer wix

我有一个安装程序来安装Windows服务.此安装程序包含一个UI对话框,允许用户指定服务名称.此服务名称存储在公共属性中.安装程序成功创建具有指定名称的服务,但是当我尝试卸载它时,安装程​​序会尝试停止并删除具有默认服务名称属性(未由用户指定)的服务.

我的服务安装代码如下所示:

...
<Property Id="SERVICE_NAME" Value="Default_Service_Name" />
...
<Component Id="C.service.exe" Guid="...">
        <File Id="service.exe" Name="$(var.service.TargetFileName)" KeyPath="yes" Vital="yes"
              Source="$(var.service.TargetPath)" />
        <ServiceInstall Id="MyServiceInstall" DisplayName="[SERVICE_NAME]" Account="[SERVICE_ACCOUNT]" Password="[SERVICE_PASSWORD]"
                        Name="[SERVICE_NAME]" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes">
        </ServiceInstall>
        <ServiceControl Id="MyServiceStart" Name="[SERVICE_NAME]" Start="install" Wait="no" />
        <ServiceControl Id="MyServiceStop" Name="[SERVICE_NAME]" Stop="both" Wait="yes" />
        <ServiceControl Id="MyServiceRemove" Name="[SERVICE_NAME]" Remove="uninstall" Wait="yes" />
      </Component>
...
Run Code Online (Sandbox Code Playgroud)

在用户指定服务名称后,我可能需要一些CA来更新SerciceControl表吗?

Bob*_*son 5

您需要保留卸载所需的任何用户提供的数据,例如将其保存到注册表中.请参阅WiX工具集的"记住属性"模式.