0

I need to run a PowerShell script to shut down specific IIS App Pools during a WiX uninstall. The CustomAction is defined as this:

<SetProperty Id="RunStopScript"
        Before ="RunStopScript"
        Sequence="execute"
        Value="&quot;C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe&quot; -NonInteractive -ExecutionPolicy Bypass -InputFormat None -NoProfile -File &quot;[INSTALLDIR]Scripts/StopAppPools.ps1&quot;" />

<CustomAction Id="RunStopScript" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Return="ignore" Impersonate="no" />

And scheduled like this:

<InstallExecuteSequence>
  <Custom Action="RunStopScript" After='InstallInitialize'>REMOVE="ALL"</Custom>
</InstallExecuteSequence>

I modified the Script so that I can see immediately when they run, and the problem is when doing an uninstall I still get the prompt that files are in use and a reboot will be needed before the scripts are ran (this prompt only pops up if the App Pools the script stops are running). The idea behind the scripts is that users won't get this prompt when doing an uninstall or major upgrade.

Valuator
  • 3,262
  • 2
  • 29
  • 53
  • Do you know what files are in use? If not you can check with Process Explorer. Can you use `Stop-Process` to end any specific processes that have handles that are causing your issue? – trebleCode Jan 30 '18 at 19:43

1 Answers1

1

The FilesInUse dialog showing or not is set by InstallValidate which happens before InstallInitialize and also happens un-elevated so you can't run a deferred custom action before InstallValidate.

You can work around this issue by using a burn bootstrapper which will launch the MSI elevated and then you can schedule your custom action before InstallValidate as an Execute="immediate" action with Impersonate="no" and it will be able to stop those IIS App pools. You'll get an ICE68 warning during compilation but you can ignore it.

Otherwise, I think there's a way you can hide the Files in use dialog. Try the suggestion in this answer. I think you'll still avoid a restart if you keep your deferred action scheduled right after InstallInitialize. This may however cause an issue if some other unexpected program is holding a file in use (notepad, hex editor for whatever reason, ect.) so something to keep in mind.

Brian Sutherland
  • 4,698
  • 14
  • 16