如何使用 WiX 设置服务的恢复选项? [英] How can I set recovery-options of a service with WiX?

查看:22
本文介绍了如何使用 WiX 设置服务的恢复选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 .wxs 文件:

<Package InstallerVersion="301"压缩=是"InstallPrivileges="提升"安装范围=perMachine"Platform="x86"/><媒体 ID="1"内阁="$(var.SkuName).cab"EmbedCab="yes"/><目录 ID="TARGETDIR"名称="SourceDir"><Directory Id="ProgramFilesFolder"><Directory Id="ManufacturereDirectory"名称="$(var.Manufacturer)"><目录 ID="产品目录"名称="$(var.ProductName)"/></目录></目录></目录><ComponentGroup Id="MainComponentGroup"><组件目录=产品目录"><文件名="$(var.MyProject.TargetFileName)"来源="$(var.MyProject.TargetPath)"键路径=是"Vital="是"/><ServiceInstall Id="服务安装"名称="$(var.ProductName)"DisplayName="$(var.ProductName)"类型=自己的进程"互动=否"开始=自动"重要=是"错误控制=正常"帐户=本地系统"></ServiceInstall><ServiceControl Id="ServiceControl_Start"名称="$(var.ProductName)"开始=安装"等待=否"/><ServiceControl Id="ServiceControl_Stop"名称="$(var.ProductName)"停止=两者"删除=卸载"等待=是"/></组件></组件组><功能 ID="主要功能"级别="1"><ComponentGroupRef Id="MainComponentGroup"/></功能><Upgrade Id="$(var.UpgradeCode)"><UpgradeVersion 属性="UPGRADEFOUND"最小=0.0.0.1"包括最小=是"Maximum="$(var.ProductVersion)" IncludeMaximum="yes"只有检测=否"IgnoreRemoveFailure="是"MigrateFeatures="yes"/></升级><CustomAction Id="ServiceRestarter"目录="产品目录"ExeCommand=""[SystemFolder]sc.exe"失败&quot;$(var.ProductName)" reset=60 actions=restart/0"冒充=否"/><安装执行序列><InstallExecute Before="RemoveExistingProducts"/><RemoveExistingProducts Before="InstallFinalize"/><Custom Action="ServiceRestarter" After="InstallFinalize"><![CDATA[未安装]]></Custom></InstallExecuteSequence></产品></Wix>

在此之前,我已经尝试过:

它显然叫 sc.exe - 但什么都没改变......

在此之前我尝试过:

<ServiceConfig Id="ServiceConfig"延迟自动启动=是"OnInstall =是"OnReinstall="是"OnUninstall="否"FailureActionsWhen="failedToStopOrReturnedError"/><ServiceConfigFailureActions Id="ServiceRestarter"OnInstall =是"OnReinstall="是"OnUninstall="否"ResetPeriod="0"><Failure Action="restartService" Delay="0"/><Failure Action="restartService" Delay="0"/><Failure Action="restartService" Delay="0"/></ServiceConfigFailureActions></ServiceInstall>

这不起作用,因为 MsiServiceConfigFailureActions 在使用安装程序时不起作用5.0,即使使用 InstallerVersion="500" 我唯一得到的就是一个错误:

<块引用>

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

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

所以...使用 CustomAction 是可行的方法(或不可行?).

我有以下日志输出

<块引用>

MSI (s) (34:28) [13:56:46:914]: Note: 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]: Note: 1: 2228 2: 3: Error 4: SELECT Message FROM Error WHERE错误 = 1722
MSI (c) (2C:0C) [13:56:46:914]:字体已创建.字符集:Req=0,Ret=0,字体:Req=MS Shell Dlg,Ret=MS Shell Dlg

错误 1722.此 Windows 安装程序包存在问题.作为安装程序的一部分运行的程序未按预期完成.请联系您的支持人员或软件包供应商.Action 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]: Note: 1: 2228 2: 3: Error 4: SELECT Message FROM Error WHERE错误 = 1709
MSI (s) (34:28) [13:56:48:849]:产品:我的产品 -- 错误 1722.此 Windows 安装程序包存在问题.作为安装程序的一部分运行的程序未按预期完成.请联系您的支持人员或软件包供应商.Action 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-extension:

这给了我以下构建错误:

<块引用>

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

我知道我可以通过命令行使用 -ext WixUtilExtension 来解决这个错误 - 但我想使用 Visual Studio 来构建......那么我该如何调整构建命令?>

唯一的机会是在我的项目中添加对 WixUtilExtension.dll 的引用.

解决方案

我可以看到您只尝试了 MSI 5.0 附带的 ServiceConfig 元素.但是,在 UtilExtension 中有 另一个 ServiceConfig 元素,它已经存在很长时间了,似乎 您在中提到的线程您的问题确认它有效.

util:ServiceConfig 元素包含您想要使用的 3 个参数:FirstFailureActionTypeSecondFailureActionTypeThirdFailureActionType,都接受相同的枚举值 - nonerebootrestartrunCommand.

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

I have following .wxs-file:

<?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>

Before that, I've tried:

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

which apparently called sc.exe - but changed nothing ...

Before that I've tried:

<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>

which did not work, as the MsiServiceConfigFailureActions table does not work if using an installer < 5.0, and even if using InstallerVersion="500" the only thing I get is an error:

Serivce 'My Product' (My Product) could not be configured. This could be a problem with the package or your permissions. Verify that you have sufficient privileges to configure system services.

(and yes, ... I've tried InstallPrivilges="elevated" also - but ... the real issue is Action="restartService" according to this)

So ... using a CustomAction is the way to go (or not?).

I have following output of the log

MSI (s) (34:28) [13:56:46:914]: Note: 1: 1722 2: ServiceRestarter 3: C:\Program Files (x86)\My Company\My Product\ 4: "C:\Windows\SysWOW64\sc.exe" failure "My Product" reset= 60 actions= restart/0
MSI (s) (34:28) [13:56:46:914]: Note: 1: 2205 2: 3: Error
MSI (s) (34:28) [13:56:46:914]: Note: 1: 2228 2: 3: Error 4: SELECT Message FROM Error WHERE Error = 1722
MSI (c) (2C:0C) [13:56:46:914]: Font created. Charset: Req=0, Ret=0, Font: Req=MS Shell Dlg, Ret=MS Shell Dlg

Error 1722. There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action ServiceRestarter, location: C:\Program Files (x86)\My Company\My Product\, command: "C:\Windows\SysWOW64\sc.exe" failure "My Product" reset= 60 actions= restart/0
MSI (s) (34:28) [13:56:48:849]: Note: 1: 2205 2: 3: Error
MSI (s) (34:28) [13:56:48:849]: Note: 1: 2228 2: 3: Error 4: SELECT Message FROM Error WHERE Error = 1709
MSI (s) (34:28) [13:56:48:849]: Product: My Product -- Error 1722. There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action ServiceRestarter, location: C:\Program Files (x86)\My Company\My Product\, command: "C:\Windows\SysWOW64\sc.exe" failure "My Product" reset= 60 actions= restart/0

Action ended 13:56:48: ServiceRestarter. Return value 3.
Action ended 13:56:48: INSTALL. Return value 3.

Can anybody help me out?

edit

I've used the old ServiceConfig-extension:

<util:ServiceConfig xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
                    FirstFailureActionType="restart"
                    SecondFailureActionType="restart"
                    ThirdFailureActionType="restart"
                    ResetPeriodInDays="1"
                    RestartServiceDelayInSeconds="20" />

which gives me a following build-error:

error CNDL0200: The ServiceInstall element contains an unhandled extension element 'util:ServiceConfig'. Please ensure that the extension for elements in the 'http://schemas.microsoft.com/wix/UtilExtension' namespace has been provided.

I know that I can resolve this error by using -ext WixUtilExtension via commandline - but I want to use Visual Studio for building ... So how can I adapt the build-command?

Only chance is to add a reference to WixUtilExtension.dll to my project.

解决方案

I can see that you've only tried the ServiceConfig element, which came with MSI 5.0. However, there's another ServiceConfig element in UtilExtension, which has been there for a long time and it seems that the thread you mention in your question confirms that it works.

The util:ServiceConfig element contains 3 parameters you'd like to use: FirstFailureActionType, SecondFailureActionType and ThirdFailureActionType, all accepting the same enumeration of values - none, reboot, restart and runCommand.

Try it out and if it works, it is far better choice than a custom action.

这篇关于如何使用 WiX 设置服务的恢复选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆