2

我有一个 WiX 设置

<MajorUpgrade Schedule="afterInstallInitialize" 
  DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />

如果在升级过程中发生错误,安装程序会回滚并恢复之前安装的版本。但是,通过自定义操作创建的计划任务会丢失并且永远不会恢复。

我用于创建/删除/回滚任务的自定义操作是:

<!-- task scheduling -->
<CustomAction Id="CreateScheduledTask" Return="check" Directory="SystemFolder"
              ExeCommand="&quot;[SystemFolder]SCHTASKS.EXE&quot; /Create /RU &quot;[TASK_DOMAIN]\[TASK_USERNAME]&quot; /RP [TASK_PASSWORD] /SC DAILY /TN &quot;Maintenance&quot; /TR &quot;[\\]&quot;[SERVICELOCATION]Maintenance.exe[\\]&quot;&quot; /ST [TASK_TIME]"
              Execute= "deferred"/>
<!-- rollback in case something went wrong -->
<CustomAction Id="CreateScheduledTask_Rollback" Execute="rollback"  Return="ignore" Directory="SystemFolder" ExeCommand="&quot;[SystemFolder]SCHTASKS.EXE&quot; /Delete /TN &quot;Maintenance&quot; /F" />
<!-- removal of task -->
<CustomAction Id="RemoveScheduledTask" Return="ignore" Directory="SystemFolder" ExeCommand="&quot;[SystemFolder]SCHTASKS.EXE&quot; /Delete /TN &quot;Maintenance&quot; /F" Execute= "immediate"/>

排队为

<InstallExecuteSequence>
  <Custom Action="CreateScheduledTask_Rollback" Before="CreateScheduledTask"></Custom>
  <Custom Action="CreateScheduledTask"  Before="InstallFinalize"></Custom>
  <Custom Action="RemoveScheduledTask"  Before="RemoveFiles">
    <![CDATA[(REMOVE="ALL")]]>
  </Custom>
</InstallExecuteSequence>

CreateScheduledTask-action 有一个条件NOT Installed,我出于测试目的删除了该条件。

谁能告诉我,为了在升级设置回滚时重新创建任务,我需要做什么?PS:我无权访问最初创建任务时使用的域、用户名或密码。

4

1 回答 1

4

您需要另一个回滚自定义操作,RemoveScheduledTask因为它基本上完成了CreateScheduledTask. 例如:

<CustomAction Id="RemoveScheduledTask_Rollback" Return="ignore" Directory="SystemFolder"
          ExeCommand="&quot;[SystemFolder]SCHTASKS.EXE&quot; /Create /RU &quot;[TASK_DOMAIN]\[TASK_USERNAME]&quot; /RP [TASK_PASSWORD] /SC DAILY /TN &quot;Maintenance&quot; /TR &quot;[\\]&quot;[SERVICELOCATION]Maintenance.exe[\\]&quot;&quot; /ST [TASK_TIME]"
          Execute="rollback" />

<InstallExecuteSequence>
   <Custom Action="RemoveScheduledTask_Rollback" Before="RemoveScheduledTask"">
    REMOVE="ALL"
   </Custom>
</InstallExecuteSequence>

您将需要访问域、用户名和密码才能以与最初相同的方式创建任务。您可以使用记住属性模式在卸载期间使属性可用,尽管您可能希望在存储密码之前添加另外几个操作来加密/解密密码。

于 2013-04-11T13:07:46.770 回答