可以根据功能选择使用相同的可执行文件注册多个Windows服务吗?

问题描述 投票:0回答:1

仅使用 Wix 工具集且仅使用标准功能,有没有办法使用不同的参数多次注册相同的可执行文件作为 Windows 服务,但是每个服务注册都取决于安装程序中选择的功能?

示例:

<Component Id="8420977C981F453ABDFA72A3A34BDAD0" Guid="{A6262383-1763-4870-81D5-C67ABDD9DD10}">
    <File Id="8BCA8B8076ADE6BBF1CF6CF91FD2A9C2" KeyPath="yes"
        Source="Output\Release\MyServiceExecutable.exe" />
    <ServiceInstall
        Type="ownProcess"
        Account="LocalSystem"
        Arguments="Feature1"
        Name="Name of service 1"
        DisplayName="Display name of service 1"
        Description="Startup and monitoring of Feature1"
        Start="auto"
        Vital="yes"
        ErrorControl="normal"
        Interactive="no">
    </ServiceInstall>
    <ServiceControl Id="0AE8B11004B7443EA7FC4827EF299239" Name="Name of service 1"
        Remove="uninstall" Stop="install" />
    <!-- The following service only to be installed if feature 2 is selected as well. Note that is
    is the same executable, just a different argument. -->
    <ServiceInstall
        Type="ownProcess"
        Account="LocalSystem"
        Arguments="Feature2"
        Name="Name of service 2"
        DisplayName="Display name of service 2"
        Description="Startup and monitoring of Feature2"
        Start="auto"
        Vital="yes"
        ErrorControl="normal"
        Interactive="no">
    </ServiceInstall>
    <ServiceControl Id="8fb32b090d034356aa2ab9fb533d2176" Name="Name of service 2"
        Remove="uninstall" Stop="install" />
</Component>

以这种方式为我需要的所有服务注册相同的可执行文件效果很好,但目前它是“全有或全无”。 我研究了条件函数,这在 ServiceInstall 中是不允许的。

我见过一些使用预处理器语句的示例,例如

<?if &feature=3 ?>

,但我不明白预处理器语句对我有什么帮助。

    

wix windows-installer wix3
1个回答
0
投票
创建自定义 WiX UI

可能是一个选项。 但是,我遇到了几乎完全相同的问题,我个人建议使用burn来制作引导程序,它应该很快就能起步。超级简单的捆绑 UI 可用于选择您希望 MSI 安装的功能和选项。然后它可以通过 MsiProperties 将这些选择传递给 MSI。

<MsiPackage Id="MyMSI" Compressed="yes" EnableFeatureSelection="yes" SourceFile="$(targetPathToYourMsiOutput)"> <MsiProperty Name="OPTION1" Value="[Option1]" /> <MsiProperty Name="OPTION2" Value="[Option2]" /> </MsiPackage>

然后您可以将它们解析为自己的 MSI 功能,您可以按如下方式控制功能级别:

<Feature Id="Service1" Title="Service1.MSI" Level="0"> <Level Value="1" Condition="OPTION1=1" /> <ComponentGroupRef Id="WhateverComponentGroupStartsThisService" /> </Feature> <Feature Id="Service2" Title="Service2.MSI" Level="0"> <Level Value="1" Condition="OPTION2=1" /> <ComponentGroupRef Id="WhateverComponentGroupStartsThisOtherService" /> </Feature>

	
© www.soinside.com 2019 - 2024. All rights reserved.