title: WiX CustomAction with elevated privileges SCHTASKS "Access Denied"
body: <p>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.</p>
  
  <p>I have another 2 CustomAction scripts called RemoveScript1 and RemoveScript2.</p>
  
  <p>They are all the same type 34 CA's with the following attributes:</p>
  
  <pre><code>&lt;CustomAction Id="XXXXXX"
                Directory="AFolder"
                ExeCommand="XXXXXX"
                Execute="deferred"
                Impersonate="no"
                Return="asyncWait" /&gt;
  </code></pre>
  
  <p>And the following install sequence.</p>
  
  <pre><code>&lt;InstallExecuteSequence&gt;
    &lt;Custom Action="RemoveScript1" Before="InstallFinalize" &gt;REMOVE="ALL"&lt;/Custom&gt;
    &lt;Custom Action="RemoveScript2" Before="InstallFinalize" &gt;REMOVE="ALL"&lt;/Custom&gt;
    &lt;Custom Action="Script1" Before="InstallFinalize" &gt;(NOT Installed) OR MaintenanceMode="Modify"&lt;/Custom&gt;
    &lt;Custom Action="Script2" Before="InstallFinalize" &gt;(NOT Installed) OR MaintenanceMode="Modify"&lt;/Custom&gt;
  &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>Example Create script:</p>
  
  <pre><code>SCHTASKS.exe /Create /TN NAME /TR "pathtosomeexe" /SC ONEVENT /EC System /MO *[System/EventID=XXXX] /F
  </code></pre>
  
  <p>Example Delete script:</p>
  
  <pre><code>SCHTASKS /Delete /TN NAME /F
  </code></pre>
  
  <p>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.</p>
  
  <ul>
  <li>MSI (s) (60:B0) [17:20:49:555]: Doing action: RemoveScript1</li>
  <li>Action start 17:20:49: RemoveScript1.</li>
  <li>Action ended 17:20:49: RemoveScript1. Return value 1.</li>
  <li>MSI (s) (60:B0) [17:20:49:649]: Executing op: ActionStart(Name=RemoveScript1,,)</li>
  <li>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,)</li>
  <li>1: RemoveScript1 2: 1631 </li>
  </ul>
  
  <p>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.</p>
  
  <p>If I create a task using the normal command line, I can delete it normally as expected.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>OS: Windows 10</p>
  
  <p>WixVersion: 3.10</p>