我已经使用 Wix 开发了 Windows 服务安装程序。服务设置为安装后自动启动。安装程序有自定义对话框,它将接受用户输入并更新 .config 文件。输入是可选的。
未提供输入时,不会更新配置文件。我可以从 services.msc 重新启动 windows 服务。如果用户提供输入,自定义操作(延迟)将更新配置文件。此自定义操作以 Impersonate="no" 模式运行。
在这种情况下,Windows 服务会在安装后自动启动,一切正常。但是当我重新启动服务时,它会抛出以下错误。
下面是安装服务的代码:
<Component Id="CMPFa85281c3_a329_4a93_a1d7_203fbccec31f" Guid="*" Directory="INSTALLLOCATION">
<Condition>
<![CDATA[Installed OR (SVCINSTALL <> 0)]]>
</Condition>
<RemoveFile Id="RmFa85281c3_a329_4a93_a1d7_203fbccec31f" Name="MyService.exe" On="both" />
<File Id="Fa85281c3_a329_4a93_a1d7_203fbccec31f" Source="$(var.BaseDir)\MyService.exe" KeyPath="yes" />
<ServiceInstall Id="InstallWindowsService" Name="MyService"
DisplayName="MyService"
Start="auto"
ErrorControl="normal"
Type="ownProcess"
Account="[USER_DOMAIN]\[SERVICEUSER]"
Password="[PASSWORD]"
Description="MyService"/>
<ServiceControl Id="sc_InstallWindowsService" Name="MyService"
Start="install" Remove="uninstall" Stop="both" Wait="no"/>
</Component>
下面是自定义操作的代码。
<CustomAction Id="UpdateConfigFiles"
Return="check"
Execute="deferred"
Impersonate="no"
BinaryKey="MyCustomAction.dll"
DllEntry="UpdateFilePath"
HideTarget="yes">
</CustomAction>
<InstallExecuteSequence>
<Custom Action="PassData" Before="UpdateConfigFiles">NOT Installed AND NOT PATCH AND NOT REMOVE</Custom>
<Custom Action="UpdateConfigFiles" Before="InstallFinalize">NOT Installed AND NOT PATCH AND NOT REMOVE</Custom>
</InstallExecuteSequence>