我正在尝试让我的安装程序在删除应用程序时使用自定义操作删除计划任务。创建“CreateScheduledTask”的自定义操作正常工作,但删除失败。
MSI (s) (B4:D8) [09:28:45:761]: Note: 1: 1721 2: RemoveScheduledTask 3: C:\Foobar\ 4: "C:\Windows\SysWOW64\SCHTASKS.EXE" /DELETE /TN "Automated Admin" /F
Info 1721.此Windows Installer程序包存在问题。无法运行此安装所需的程序。请联系您的支持人员或包装供应商。操作:RemoveScheduledTask,位置:C:\ Foobar \,命令:“C:\ Windows \ SysWOW64 \ SCHTASKS.EXE”/ DELETE / TN“自动管理”/ F MSI(s4)(B4:44)[09:28:45:777]:调用远程自定义操作。 DLL:C:\ Windows \ Installer \ MSIBB52.tmp,入口点:CommitIIS7ConfigTransaction
如果我运行
,语法是正确的"C:\Windows\SysWOW64\SCHTASKS.EXE" /DELETE /TN "Automated Admin" /F
从命令行中正确删除任务。
<!-- Code for setting the automated task-->
<CustomAction Id="CreateScheduledTask"
Return="check"
Impersonate="no"
Execute="deferred"
Directory="INSTALLLOCATION"
ExeCommand=""[SystemFolder]SCHTASKS.EXE" /CREATE /SC MINUTE /MO 15 /TN "Automated Admin" /TR "[AutomatedAdmin]FooBar.exe" /RU "NT Authority\System" /RP /RL HIGHEST" />
Wix片段
<CustomAction Id="RemoveScheduledTask"
Return="ignore"
Impersonate="no"
Execute="deferred"
Directory="INSTALLLOCATION"
ExeCommand=""[SystemFolder]SCHTASKS.EXE" /DELETE /TN "Automated Admin" /F" />
<InstallExecuteSequence>
<Custom Action="CreateScheduledTask" Before="InstallFinalize">NOT Installed</Custom>
<Custom Action="RemoveScheduledTask" Before="RemoveFiles">REMOVE="ALL"</Custom>
</InstallExecuteSequence>
答案 0 :(得分:3)
您的代码看起来正确,这是我的配置,编译为x86 .msi,我在Windows 8.1 x64 / x86和Windows Server 2008r2 x64上进行了测试。将UAC设置为默认值并禁用。 (.msi将提示管理员权限)
<CustomAction Id="TaskDelete" Return="ignore" Execute="deferred" Directory="TARGETDIR" Impersonate="no"
ExeCommand="SCHTASKS.EXE /DELETE /TN "My Client Service" /F" />
<CustomAction Id="TaskCreate" Return="check" Execute="deferred" Directory="TARGETDIR" Impersonate="no"
ExeCommand="SCHTASKS.EXE /CREATE /SC MINUTE /MO 20 /TN "My Client Service" /TR "sc.exe start My_Client_Service" /RU SYSTEM /RP /RL HIGHEST /F" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="My Company" >
...components...
</Directory>
</Directory>
</Directory>
<InstallExecuteSequence>
<!--Remove task on Uninstall or Upgrade-->
<Custom Action='TaskDelete' Before="TaskCreate">REMOVE="ALL"</Custom>
<!--Add task on Install or Upgrade-->
<Custom Action='TaskCreate' Before="InstallFinalize">(NOT Installed) OR UPGRADINGPRODUCTCODE</Custom>
</InstallExecuteSequence>