title: WiX uninstall - close application before Restart Manager
body: <p>I have an installer done with WiX. When it's done installing, it starts an application that injects some code in the Explorer process.</p>
  
  <p>Currently when I uninstall, the Restart Manager kicks in and offers to shut down my application and Explorer. Instead of that I want to close my application manually (this is done by running it again with -exit on the command line). I have a custom action that does it.</p>
  
  <p>Here's what I tried so far:</p>
  
  <pre><code>&lt;CustomAction ExeCommand="-exit" FileKey="MyApp.exe" Id="CloseMyApp" Impersonate="yes" Return="ignore" /&gt;
  
  &lt;InstallExecuteSequence&gt;
      &lt;RemoveExistingProducts After="InstallInitialize" /&gt;
      &lt;Custom Action="CloseMyApp" Before="RemoveFiles" /&gt;
  &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>This doesn't work. The action is done way after the Restart Manager session. So the Restart Manager pops up and asks to close my app and Explorer. The action runs later, but by then the app is already gone.</p>
  
  <p>So then I tried this:</p>
  
  <pre><code>&lt;InstallExecuteSequence&gt;
      &lt;RemoveExistingProducts After="InstallInitialize" /&gt;
      &lt;Custom Action="CloseMyApp" Before="RemoveExistingProducts" /&gt;
  &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>This also doesn't work. The action is done too late still. I also get "warning LGHT1076 : ICE63: Some action falls between InstallInitialize and RemoveExistingProducts.".</p>
  
  <p>So basically - how do I execute my custom action during uninstall and before the Restart Manager session?</p>
  
  <p>I'm guessing if I use Impersonate="no" it might run at the right time, however that's not an option. That's because the new process must run for the same user as the process that has to close because it looks up its window and sends messages. That's much trickier to do if the processes belong to different users.</p>
  
  <p>Any ideas?</p>