如何使用WiX设置服务的恢复选项?

And*_*air 16 wix wix3.5 wix3.6

我有以下.wxs文件:

<?xml version="1.0" encoding="UTF-8"?>
<?define ProductVersion="x.x.x.x" ?>
<?define UpgradeCode="{**MYGUID**}" ?>
<?define Manufacturer="My Company" ?>
<?define ProductName="My Product" ?>
<?define SkuName="MyProduct" ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*"
             Name="$(var.ProductName)"
             Language="1033"
             Version="$(var.ProductVersion)"
             Manufacturer="$(var.Manufacturer)"
             UpgradeCode="$(var.UpgradeCode)">
        <Package InstallerVersion="301"
                 Compressed="yes"
                 InstallPrivileges="elevated"
                 InstallScope="perMachine"
                 Platform="x86" />
        <Media Id="1"
               Cabinet="$(var.SkuName).cab"
               EmbedCab="yes" />
        <Directory Id="TARGETDIR"
                   Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="ManufacturereDirectory"
                           Name="$(var.Manufacturer)">
                    <Directory Id="ProductDirectory"
                               Name="$(var.ProductName)" />
                </Directory>
            </Directory>
        </Directory>
        <ComponentGroup Id="MainComponentGroup">
            <Component Directory="ProductDirectory">
                <File Name="$(var.MyProject.TargetFileName)"
                      Source="$(var.MyProject.TargetPath)"
                      KeyPath="yes"
                      Vital="yes" />
                <ServiceInstall Id="SeviceInstall"
                                Name="$(var.ProductName)"
                                DisplayName="$(var.ProductName)"
                                Type="ownProcess"
                                Interactive="no"
                                Start="auto"
                                Vital="yes"
                                ErrorControl="normal"
                                Account="LOCALSYSTEM">
                </ServiceInstall>
                <ServiceControl Id="ServiceControl_Start"
                                Name="$(var.ProductName)"
                                Start="install"
                                Wait="no" />
                <ServiceControl Id="ServiceControl_Stop"
                                Name="$(var.ProductName)"
                                Stop="both"
                                Remove="uninstall"
                                Wait="yes" />
            </Component>
        </ComponentGroup>
        <Feature Id="MainFeature"
                 Level="1">
            <ComponentGroupRef Id="MainComponentGroup" />
        </Feature>
        <Upgrade Id="$(var.UpgradeCode)">
            <UpgradeVersion Property="UPGRADEFOUND"
                            Minimum="0.0.0.1" IncludeMinimum="yes"
                            Maximum="$(var.ProductVersion)" IncludeMaximum="yes"
                            OnlyDetect="no"
                            IgnoreRemoveFailure="yes"
                            MigrateFeatures="yes"/>
        </Upgrade>
        <CustomAction Id="ServiceRestarter"
                      Directory="ProductDirectory"
                      ExeCommand="&quot;[SystemFolder]sc.exe&quot; failure &quot;$(var.ProductName)&quot; reset= 60 actions= restart/0"
                      Impersonate="no" />
        <InstallExecuteSequence>
            <InstallExecute Before="RemoveExistingProducts" />
            <RemoveExistingProducts Before="InstallFinalize" />
            <Custom Action="ServiceRestarter" After="InstallFinalize"><![CDATA[NOT Installed]]></Custom>
        </InstallExecuteSequence>
    </Product>
</Wix>
Run Code Online (Sandbox Code Playgroud)

在此之前,我尝试过:

<CustomAction Id="ServiceRestarter"
              Property="QtExecCmdLine"
              Value='"[SystemFolder]sc.exe" failure "$(var.ProductName)" reset= 60 actions= restart/0' />
Run Code Online (Sandbox Code Playgroud)

显然叫做sc.exe- 但没有改变......

在此之前我尝试过:

<ServiceInstall Id="SeviceInstall"
                Name="$(var.ProductName)"
                DisplayName="$(var.ProductName)"
                Type="ownProcess"
                Interactive="no"
                Start="auto"
                Vital="yes"
                ErrorControl="normal"
                Account="LOCALSYSTEM">
    <ServiceConfig Id="ServiceConfig"
                   DelayedAutoStart="yes"
                   OnInstall="yes"
                   OnReinstall="yes"
                   OnUninstall="no"
                   FailureActionsWhen="failedToStopOrReturnedError" />
    <ServiceConfigFailureActions Id="ServiceRestarter"
                                 OnInstall="yes"
                                 OnReinstall="yes"
                                 OnUninstall="no"
                                 ResetPeriod="0">
        <Failure Action="restartService" Delay="0" />
        <Failure Action="restartService" Delay="0" />
        <Failure Action="restartService" Delay="0" />
    </ServiceConfigFailureActions>
</ServiceInstall>
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为如果使用安装程序<5.0,MsiServiceConfigFailureActions不起作用,即使使用InstallerVersion="500"我得到的唯一的东西是一个错误:

无法配置Serivce"我的产品"(我的产品).这可能是包或您的权限的问题.验证您是否具有足够的权限来配置系统服务.

(是的,......我也试过了InstallPrivilges="elevated"- 但......真正的问题是Action="restartService"根据这个)

所以...使用a CustomAction是要走的路(或不是?).

我有以下日志输出

MSI(s)(34:28)[13:56:46:914]:注意:1:1722 2:ServiceRestarter 3:C:\ Program Files(x86)\ My Company\My Product\4:"C:\ Windows\SysWOW64\sc.exe"失败"我的产品"reset = 60 actions = restart/0
MSI(s)(34:28)[13:56:46:914]:注意:1:2205 2:3:错误
MSI(s)(34:28)[13:56:46:914]:注意:1:2228 2:3:错误4:Message选自ErrorWHERE Error= 1722
MSI(c)(2C:0C)[13:56: 46:914]:创建了字体.字符集:Req = 0,Ret = 0,字体:Req = MS Shell Dlg,Ret = MS Shell Dlg

错误1722.此Windows Installer程序包存在问题.作为设置的一部分运行的程序没有按预期完成.请联系您的支持人员或包装供应商.操作ServiceRestarter,位置:C:\ Program Files(x86)\ My Company\My Product \,命令:"C:\ Windows\SysWOW64\sc.exe"失败"我的产品"reset = 60 actions = restart/0
MSI( s)(34:28)[13:56:48:849]:注意:1:2205 2:3:错误
MSI(s)(34:28)[13:56:48:849]:注意:1: 2228 2:3:错误4:SELECT MessageFROM ErrorWHERE Error= 1709
MSI(s)(34:28)[13:56:48:849]:产品:我的产品 - 错误1722.此Windows Installer程序包有问题.作为设置的一部分运行的程序没有按预期完成.请联系您的支持人员或包装供应商.操作ServiceRestarter,位置:C:\ Program Files(x86)\ My Company\My Product \,命令:"C:\ Windows\SysWOW64\sc.exe"失败"我的产品"reset = 60 actions = restart/0

行动结束13:56:48:ServiceRestarter.返回值3.
行动结束13:56:48:安装.返回值3.

有人可以帮帮我吗?

编辑

我用过旧的ServiceConfig扩展:

<util:ServiceConfig xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
                    FirstFailureActionType="restart"
                    SecondFailureActionType="restart"
                    ThirdFailureActionType="restart"
                    ResetPeriodInDays="1"
                    RestartServiceDelayInSeconds="20" />
Run Code Online (Sandbox Code Playgroud)

这给了我一个以下构建错误:

错误CNDL0200:ServiceInstall元素包含未处理的扩展元素'util:ServiceConfig'.请确保已提供" http://schemas.microsoft.com/wix/UtilExtension "命名空间中元素的扩展名.

我知道我可以通过使用-ext WixUtilExtension命令行解决此错误- 但我想使用Visual Studio进行构建...那么我如何调整build-command?

只有机会是添加WixUtilExtension.dll对我的项目的引用.

Yan*_*nko 21

我可以看到你只尝试了MSI 5.0附带的ServiceConfig元素.然而,UtilExtension中另一个ServiceConfig元素,它已存在很长时间了,你在问题中提到的线程似乎证实它有效.

UTIL:ServiceConfig元素包含3个参数,你想使用:FirstFailureActionType,SecondFailureActionTypeThirdFailureActionType,所有接受值相同枚举- ,,none 和.rebootrestartrunCommand

尝试一下,如果它有效,它是比自定义动作更好的选择.

  • 只需将`xmlns:util ="http://schemas.microsoft.com/wix/UtilExtension"添加到根`WiX`元素 (5认同)

dav*_*zen 11

对于使用VS2015构建的WIX V 4.0,以下工作:

1:确保WIX项目引用了WixUtilExtension.dll程序集.

2:将http://wixtoolset.org/schemas/v4/wxs/util ns 添加到根Wix元素.请注意,这是WIX 4.0的正确NS(与先前版本不同,不是http://schemas.microsoft.com/wix/UtilExtension).

<Wix
  xmlns="http://wixtoolset.org/schemas/v4/wxs"
  xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"
  >
Run Code Online (Sandbox Code Playgroud)

3:确保ServiceConfig元素的前缀为正确的命名空间引用.

<ServiceInstall
      Id="MyService"
      Type="ownProcess"
      Name="MyService"
      DisplayName="MyService"
      Description="My Service"
      Start="auto"
      Account="[SERVICEACCOUNT]"
      Password="[SERVICEPASSWORD]"
      ErrorControl="normal"
    >

      <util:ServiceConfig
        FirstFailureActionType='restart'
        SecondFailureActionType='restart'
        ThirdFailureActionType='restart'            
        RestartServiceDelayInSeconds='30'
        ResetPeriodInDays='1'/>

</ServiceInstall>
Run Code Online (Sandbox Code Playgroud)

  • util:ServiceConfig也适用于WIX版本3.10.0.1503,使用xmlns:util ="http://schemas.microsoft.com/wix/UtilExtension"定义和.dll参考 (4认同)