Can I use Wix InstallService to set the recovery options for a Windows Service, and if so how ? I couldn't find any parameters for passing in the recovery option settings.
我可以使用Wix InstallService设置Windows服务的恢复选项吗?如果可以,如何设置?我找不到任何参数来传递恢复选项设置。
Alternately how can I run sc.exe to set the service recovery options after the install has completed from the WiX installer.
或者,如何在从Wix安装程序完成安装后运行sc.exe来设置服务恢复选项。
I found this Wix code elsewhere but it seems to do nothing. Where exactly in the WiX package.wsx should this go to ensure it gets called?
我在别处找到了这个Wix代码,但它似乎什么都不起作用。Wix包中的确切位置。wsx应该放在哪里以确保它被调用?
<CustomAction Id="SetRecoveryOptions"
Directory="INSTALLFOLDER"
Execute="immediate"
Impersonate="no"
ExeCommand="cmd.exe /c "sc failure MyWindowsPService reset= 0 actions= restart/60000/restart/60000/restart/60000""
Return="asyncNoWait" />
<InstallExecuteSequence>
<Custom Action="SetRecoveryOptions"
After="InstallFinalize" />
</InstallExecuteSequence>
The full Wix package file
完整的Wix程序包文件
<?xml version="1.0" encoding="UTF-8"?>
<!-- Define the variables in "$(var.*) expressions" -->
<?define Name = "My Windows Service" ?>
<?define Manufacturer = "XYZ Pty Ltd" ?>
<?define Version = "1.0.1.0" ?>
<?define UpgradeCode = "9ED3FF33-8718-444E-B44B-69A34433B7E98" ?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="$(Name)"
Manufacturer="$(Manufacturer)"
Version="$(Version)"
UpgradeCode="$(var.UpgradeCode)"
Compressed="true">
<!-- Allow upgrades and prevent downgrades -->
<MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />
<!-- Define the directory structure -->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<!-- Create a folder inside program files -->
<Directory Id="ROOTDIRECTORY" Name="$(var.Manufacturer)">
<!-- Create a folder within the parent folder given the name -->
<Directory Id="INSTALLFOLDER_" Name="$(Name)" />
</Directory>
</Directory>
</Directory>
<MediaTemplate EmbedCab="yes" />
<ComponentGroup Id="ProgramFiles" Directory="INSTALLFOLDER_">
<Component Id="ABC.dll" Guid="*">
<File Id="ABC.dll" KeyPath="true" Source="$(var.MyWindowsServices.TargetDir)\ABC.dll" />
</Component>
...
</ComponentGroup>
<!-- The files inside this DirectoryRef are linked to
the App.MyWindowsService directory via INSTALLFOLDER -->
<DirectoryRef Id="INSTALLFOLDER_">
<!-- Create a single component which is the App.MyWindowsService.exe file -->
<Component Id="ServiceExecutable" Bitness="always64">
<!-- Copies the MyWindowsServices.exe file using the
project reference preprocessor variables -->
<File Id="MyWindowsServices.exe"
Source="$(var.MyWindowsServices.TargetDir)\MyWindowsServices.exe"
KeyPath="true" />
<!-- Remove all files from the INSTALLFOLDER on uninstall -->
<RemoveFile Id="ALLFILES" Name="*.*" On="both" />
<!-- Tell WiX to install the Service -->
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Name="MyWindowsService"
DisplayName="$(Name)"
Description="My Windows Service"
Account=".\LocalSystem"
Start="auto"
ErrorControl="normal" />
<!-- Tell WiX to start the Service -->
<ServiceControl Id="StartService"
Start="install"
Stop="both"
Remove="uninstall"
Name="MyWIndowsServices"
Wait="true" />
</Component>
</DirectoryRef>
<CustomAction Id="SetRecoveryOptions"
Directory="INSTALLFOLDER"
Execute="immediate"
Impersonate="no"
ExeCommand="cmd.exe /c "sc failure MyWindowsServices reset= 0 actions= restart/60000/restart/60000/restart/60000""
Return="asyncNoWait" />
<InstallExecuteSequence>
<Custom Action="SetRecoveryOptions"
After="InstallFinalize" />
</InstallExecuteSequence>
<!-- Tell WiX to install the files -->
<Feature Id="Service" Title="MyWindowsServices Setup" Level="1">
<ComponentRef Id="ServiceExecutable" />
<ComponentGroupRef Id="ProgramFiles" />
</Feature>
</Package>
</Wix>
EDIT:
编辑:
SO I have half the answer now. This now works as long as I run msiexec from an admin command line. Any idea how I can get the installer to run the custom command with the same installer privileges since it is already running as admin.
所以我现在有了一半的答案。现在,只要我从管理命令行运行msiexec,它就可以工作。我想知道如何让安装程序以相同的安装程序权限运行自定义命令,因为它已经以管理员身份运行。
<CustomAction Id="SetRecoveryOptions"
Directory="INSTALLFOLDER_"
Execute="immediate"
Impersonate="no"
ExeCommand="[SystemFolder]sc.exe failure MyWindowsService reset= 0 actions= restart/60000/restart/60000/restart/60000"
Return="ignore" />
<InstallExecuteSequence>
<Custom Action="SetRecoveryOptions"
OnExit="success" />
</InstallExecuteSequence>
更多回答
No I didn't find that will give it a try because running sc.exe doesnt seem to be working.
不,我没有发现这会试一试,因为运行sc.exe似乎不起作用。
Can you please provide an example of actual usage - the documentation is really quite obtuse. Thanks
你能提供一个实际使用的例子吗--文档真的很迟钝。谢谢
Also it seems that does not configure the service failure while running. That seems to be related to install failures ?
似乎也没有配置运行时的服务故障。这似乎与安装失败有关?
优秀答案推荐
It seems like the util:ServiceConfig element should do what you want. For example, adding to your ServiceExecutable Component:
看起来util:ServiceConfig元素应该做您想要做的事情。例如,添加到ServiceExecutable组件:
<Component Id='ServiceExecutable' ...>
...
<util:ServiceConfig Name='YourServiceName' FirstFailureActionType='restart'
RestartServiceDelayInSeconds='60000' ... />
</Component>
That is way more robust than shelling out to sc.exe.
这比向sc.exe注资要稳健得多。
Update: Given access to the OP's full source code, a more complete example might look like this:
更新:如果可以访问OP的完整源代码,更完整的示例可能如下所示:
Install the Nuget Wix Util Extensions in Visual Studio
Add the WiX extension's namespace following to the package.wxs file (second line)
在Visual Studio中安装Nuget Wix Util扩展,将Wix扩展的名称空间添加到Package.wxs文件(第二行)
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
...
Added the util:ServiceConfig
to the service executable component
将util:ServiceConfig添加到服务可执行组件
<!-- Create a single component for WindowsService.exe -->
<Component>
<!-- Installs the WindowsServices.exe file -->
<File Id="WindowsServices.exe"
Source="WindowsServices.exe" />
<!-- Tell Windows Installer to install the Service -->
<ServiceInstall Id="ServiceInstaller"
Type="ownProcess"
Name="WindowsService"
DisplayName="$(Name)"
Description="Windows Service"
Account=".\LocalSystem"
Start="auto"
ErrorControl="normal">
<!-- Update the failure handling -->
<util:ServiceConfig
FirstFailureActionType="restart"
RestartServiceDelayInSeconds="10000"
SecondFailureActionType="restart"
ThirdFailureActionType="restart"
/>
</ServiceInstall>
<!-- Tell WiX to start the Service -->
<ServiceControl Id="StartService"
Start="install"
Stop="both"
Remove="uninstall"
Name="WindowsService"
Wait="true" />
</Component>
更多回答
Thanks, I will take a look at that. SC is working fine now, if it runs deferred it runs as admin but as you point out it's not very elegant.
谢谢,我会去看看的。SC现在运行得很好,如果它延迟运行,它将以管理员身份运行,但正如您所指出的那样,它并不是很优雅。
You might have to also provide more detailed instructions or a link to instructions for installing and using the extension. Add via a project reference just leads to a dialog for browsing the local file system.
您可能还必须提供更详细的说明或指向安装和使用该扩展的说明的链接。通过项目引用添加只会导致一个用于浏览本地文件系统的对话框。
I used the Nuget to install the Wix util extension and added the following to the xmlns:util="schemas.microsoft.com/wix/NetFxExtension" but still get the following error: Severity Code Description Project File Line Suppression State Error WIX0200 The Component element contains an unhandled extension element 'ServiceConfig'. Please ensure that the extension for elements in the 'schemas.microsoft.com/wix/NetFxExtension' namespace has been provided.
我使用NuGet安装了Wix Util扩展,并将以下内容添加到xmlns:util=“schemas.microsoft.com/wix/NetFxExtension”中,但仍收到以下错误:严重性代码描述项目文件行抑制状态错误WIX0200Component元素包含未经处理的扩展元素‘ServiceConfig’。请确保已提供‘schemas.microsoft.com/wix/NetFxExtension’命名空间中元素的扩展名。
The goal on StackOverflow is to answer the question asked. It is not a goal to provide a tutorial that starts from zero to the final answer. There is already documentation if you need to learn the basics (for example, firegiant.com/docs/heatwave/extensions-and-references).
StackOverflow的目标是回答所提出的问题。提供从零开始到最终答案的教程并不是一个目标。如果您需要学习基础知识(例如,firegiant.com/docs/heatwave/extensions-and-references).),已有相关文档
我是一名优秀的程序员,十分优秀!