dev*_*nkd 8 windows-installer windows-services wix
我正在尝试为我的Windows服务创建一个WiX MSI安装程序,它将安装该服务但不启动它.我似乎无法找到解释如何做到这一点或任何可能的解释.
我试图删除我用于启动服务的ServiceControl以及在ServiceInstall上切换Start属性而没有任何运气.必须有可能做到这一点,对吗?我只是希望MSI文件安装该服务,并让用户在需要时启动它.
<Component Id="ServiceInstaller" Guid="9e578e3d-0339-425c-8633-f54ffaaa4921">
<ServiceInstall Id="ReportingServiceInstaller"
Type="ownProcess"
Vital="yes"
Name="WindowsService.exe"
DisplayName="WindowsService"
Description="Wickedly awesome and amazing service."
ErrorControl="ignore"
Account="NT AUTHORITY\LocalService"
Start="auto"
Interactive="no" />
<ServiceControl Id="ServiceControl_Stop"
Name="WindowsService.exe"
Stop="both"
Remove="uninstall"
Wait="no" />
</Component>
Run Code Online (Sandbox Code Playgroud)
小智 8
不要使用ServiceControl元素,因为它将启动和停止服务.通过调用它,您要求安装程序对服务执行某些操作.您只需要调用ServiceInstall来创建服务.正如Stefan Wanitzek建议的那样,您应该在ServiceInstall的Start属性中使用demand.这是为了在用户重新启动计算机时使您的服务无法开始运行.如果您的安装程序也使用安装服务安装.exe作为文件.我建议使用以下代码:
<Component Id="ServiceInstaller" Guid="3e412e3d-0339-325c-8633-f54ffaaa4921">
<File Id="WindowsService.exe"
Name="WindowsService.exe"
KeyPath="yes"
Source="Path to the EXE"/>
<ServiceInstall Id="ReportingServiceInstaller"
Type="ownProcess"
Vital="yes"
Name="WindowsService"
DisplayName="WindowsService"
Description="Wickedly awesome and amazing service."
ErrorControl="ignore"
Account="NT AUTHORITY\LocalService"
Start="demand"
Interactive="no" />
</Component>
Run Code Online (Sandbox Code Playgroud)
devfunkd的解决方案是正确的,但是有几个问题需要首先讨论。
第一,您可以消除 ServiceControl,但也可以仅删除 Start 属性。这有助于在更新时停止服务。不,Start 没有“none”选项,也不能写入 Start="",这将允许使用简单的变量而不是复制粘贴整个组件。
第二,每当更新服务时,RestartManager 都会参与其中。如果服务正在运行,则服务被停止,然后安装程序会按照指示执行操作,包括不启动服务,然后 RestartManager 恢复服务的原始状态(已启动)。我花了一天时间才弄清楚。
请注意,您可以禁用安装程序与 RestartManager 的交互(请参阅https://learn.microsoft.com/en-us/windows/desktop/Msi/msirestartmanagercontrol),但是您需要确保如果出现以下情况则不需要重新启动:安装程序会偶然发现正在使用的文件。
换句话说,无论您完全删除 ServiceControl 还是仅删除 Start 属性,为了确保服务在更新后不会启动,您需要在安装之前手动停止它们。
| 归档时间: |
|
| 查看次数: |
4037 次 |
| 最近记录: |