2
votes

I am trying to get my installer to use a custom action to remove a scheduled task when the application is removed. The custom action for create "CreateScheduledTask" works correctly, however the remove fails.

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.There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor. Action: RemoveScheduledTask, location: C:\Foobar\, command: "C:\Windows\SysWOW64\SCHTASKS.EXE" /DELETE /TN "Automated Admin" /F MSI (s) (B4:44) [09:28:45:777]: Invoking remote custom action. DLL: C:\Windows\Installer\MSIBB52.tmp, Entrypoint: CommitIIS7ConfigTransaction

The syntax is correct if I run

"C:\Windows\SysWOW64\SCHTASKS.EXE" /DELETE /TN "Automated Admin" /F 

from the command line it correctly removes the task.

<!-- Code for setting the automated task-->
<CustomAction Id="CreateScheduledTask" 
Return="check" 
Impersonate="no" 
Execute="deferred" 
Directory="INSTALLLOCATION" 
ExeCommand="&quot;[SystemFolder]SCHTASKS.EXE&quot; /CREATE /SC MINUTE /MO 15 /TN &quot;Automated Admin&quot;  /TR &quot;[AutomatedAdmin]FooBar.exe&quot; /RU &quot;NT Authority\System&quot; /RP /RL HIGHEST" />

Wix fragments are

<CustomAction Id="RemoveScheduledTask" 
Return="ignore" 
Impersonate="no" 
Execute="deferred" 
Directory="INSTALLLOCATION" 
ExeCommand="&quot;[SystemFolder]SCHTASKS.EXE&quot; /DELETE /TN &quot;Automated Admin&quot; /F" />

<InstallExecuteSequence>
  <Custom Action="CreateScheduledTask" Before="InstallFinalize">NOT Installed</Custom>
  <Custom Action="RemoveScheduledTask" Before="RemoveFiles">REMOVE="ALL"</Custom>
</InstallExecuteSequence>
1
I have the exact same issue and configuration. The installer is x86, and runs perfectly fine on several x64 computers, but fails with this issue on first install on x86 Win 8 Pro tablet.Brent
Looks like the CustomAction for my x86 tablet is likely not running as admin. (Even though UAC admin prompt for install) as when I manually add the task it isn't deleted by install.Brent
@Brent Are you able to remove a task with the installed normally? Remove never works for me. Can you post you wix fragments?Cookie
it was all working fine before, I think that was because I had UAC fully disabled. I'm working with trying to get it to work with UAC enabled to default level. I'll post the configuration as answer in a bit. Trying to figure this out.Brent
Oh the issue with uninstall on tablet not working is I had previous version (quite old) installed and the uninstaller was hanging. So once I fixed dependency and got it uninstalled everything is working properly on it now.Brent

1 Answers

3
votes

Your code looks correct, here is my config which compiles to x86 .msi and I tested on Windows 8.1 x64/x86 and Windows Server 2008r2 x64. With UAC set to default and disabled. (.msi will prompt for admin permission)

<CustomAction Id="TaskDelete" Return="ignore" Execute="deferred" Directory="TARGETDIR" Impersonate="no"
 ExeCommand="SCHTASKS.EXE /DELETE /TN &quot;My Client Service&quot; /F" />

<CustomAction Id="TaskCreate" Return="check" Execute="deferred" Directory="TARGETDIR" Impersonate="no" 
 ExeCommand="SCHTASKS.EXE /CREATE /SC MINUTE /MO 20 /TN &quot;My Client Service&quot; /TR &quot;sc.exe start My_Client_Service&quot; /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>