My installer currently installs a few files to a directory and then executes some CustomAction scripts to create 2 scheduled tasks named Script1 and Script2.
I have another 2 CustomAction scripts called RemoveScript1 and RemoveScript2.
They are all the same type 34 CA's with the following attributes:
<CustomAction Id="XXXXXX"
Directory="AFolder"
ExeCommand="XXXXXX"
Execute="deferred"
Impersonate="no"
Return="asyncWait" />
And the following install sequence.
<InstallExecuteSequence>
<Custom Action="RemoveScript1" Before="InstallFinalize" >REMOVE="ALL"</Custom>
<Custom Action="RemoveScript2" Before="InstallFinalize" >REMOVE="ALL"</Custom>
<Custom Action="Script1" Before="InstallFinalize" >(NOT Installed) OR MaintenanceMode="Modify"</Custom>
<Custom Action="Script2" Before="InstallFinalize" >(NOT Installed) OR MaintenanceMode="Modify"</Custom>
</InstallExecuteSequence>
Example Create script:
SCHTASKS.exe /Create /TN NAME /TR "pathtosomeexe" /SC ONEVENT /EC System /MO *[System/EventID=XXXX] /F
Example Delete script:
SCHTASKS /Delete /TN NAME /F
The create scripts execute fine, however, the delete scripts do not seem to work. When checking the logs I see the following lines related to RemoveScriptX.
- MSI (s) (60:B0) [17:20:49:555]: Doing action: RemoveScript1
- Action start 17:20:49: RemoveScript1.
- Action ended 17:20:49: RemoveScript1. Return value 1.
- MSI (s) (60:B0) [17:20:49:649]: Executing op: ActionStart(Name=RemoveScript1,,)
- MSI (s) (60:B0) [17:20:49:649]: Executing op: CustomActionSchedule(Action=RemoveScript1,ActionType=3234,Source=AFolder,Target=C:\Windows\SysWOW64\SCHTASKS.exe /Delete /TN NAME /F,)
- 1: RemoveScript1 2: 1631
When I try to delete these scripts created by the installer, using the normal command line, I get "ERROR: Access is denied." . Which is great! It means the scheduled tasks were created by admin. I can delete the task using the admin command line as expected.
If I create a task using the normal command line, I can delete it normally as expected.
I should note I have tried both InstallScope = perMachine, and perUser. The only difference it seems is that I have to run the actual installer as Admin for perUser to access ProgramFiles directory for the installation of the other files.
Why are my delete scripts not using admin/elevated privileges? Have I missed something stupid? I had assumed "1631" was the error code returned from SCHTASKS.exe, please correct me if I am wrong.
OS: Windows 10
WixVersion: 3.10