I have been working on this issue for days but can't find 'good' solution, please bear with me.
The task is running PowerShell script that wraps the calls to 'netsh advfirewall firewall add ...', obviously this needs elevated privilege. Also, in this PowerShell script, different exit codes are set for success or failures. Everything is fine if define a deferred WiX custom action, i.e. if succeed, a dialog about successful firewall change shows, if failed, installation rolls back. However, our customer likes to have the installer:
"Don't let MSI installation rollback if PowerShell script fails, but show some nice warning message on UI dialog at the the end of installation"
In order to wrap different exit codes, I added .NET custom action to invoke Powershell script in C# method and tried to pass it back as CustomActionData property to MSI installer. Unfortunately, I couldn't achieve this and I believe it is because deferred action can't interact with the MSI database, see this post stackoverflow question.
So, in order to pass exit code from .NET custom action back, I think 'immediate' action would set properties. I knew by default, 'immediate' action can not be elevated, but how about in .NET custom action method, can I force Powershell Script to be run as admin in C# method?
In general, is there any other way to achieve our goal. Just recap:
- run PowerShell with elevated privilege;
- don't rollback installation if Powershell script fails, instead, show different UI with different Powershell script exit codes.
Any answer is greatly appreciated. Thank you.