0

我正在使用 Wix 安装 Windows 服务,但需要选择使用 LocalSystem 帐户或使用用户提供的帐户。我应该如何在硬编码值和用户值之间切换?对于我拥有的服务:

<ServiceInstall Id="ServiceInstaller" Type="ownProcess" Vital="yes" Start="auto" 
    Account="[SERVICELOGONUSER]" Password="[SERVICELOGONPASSWORD]" ErrorControl="normal" 
    Interactive="no"/>

在 UI 中,我有以下属性:

<Property Id="SERVICELOGONUSER" Value="LocalSystem"/>

在一个对话框中,我有:

<Control Type="CheckBox" Width="200" Height="25" X="25" Y="75" Id="LocalCheckBox" 
    Property="UseLocalSystem" CheckBoxValue="1" Text="Use LocalSystem Account"/>
<Control Type="Edit" Width="200" Height="15" X="25" Y="115" Id="AccountTextbox" 
    Property="SERVICELOGONUSER">
    <Condition Action="disable">UseLocalSystem = 1</Condition>
    <Condition Action="enable"><![CDATA[UseLocalSystem <>1]]></Condition
</Control>

但这只会显示用户可以编辑的硬编码值。

4

1 回答 1

1

UseLocalSystem我建议使用您的属性制作两个具有互斥条件的组件,如下所示:

<Component Id="LocalSystem_Service" Guid="{A-GUID}">
  <Condition> UseLocalSystem = 1 </Condition>
  <File Id="SvcFile_Local" Name="Service.exe" Source="Service.exe"/>
  <ServiceInstall Id="ServiceInstaller" Type="ownProcess" Vital="yes" Start="auto" 
    Account="LocalSystem" ErrorControl="normal" Interactive="no"/>
</Component>

<Component Id="User_Service" Guid="{ANOTHER-GUID}">
  <Condition> <![CDATA[UseLocalSystem <>1]]> </Condition>
  <File Id="SvcFile_User" Name="Service.exe" Source="Service.exe" />
  <ServiceInstall Id="ServiceInstaller" Type="ownProcess" Vital="yes" Start="auto" 
    Account="[SERVICELOGONUSER]" Password="[SERVICELOGONPASSWORD]" ErrorControl="normal" 
    Interactive="no"/>
</Component>

WiX 有一个限制,如果您在两个地方需要相同的文件,则需要File在每个地方都有一个元素,这就是为什么我有两个File不同的元素Id。不过不用担心,由于有了智能布线,WiX 工具集只会在组件之间压缩重复的内容一次。

这样,用户是否开始更改SERVICELOGONUSERandSERVICELOGONPASSWORD并决定使用它并不重要LocalSystem

希望这可以帮助!

于 2015-08-14T05:17:14.367 回答