5

I have a WiX installer that needs to run a Powershell script after install. I've gotten to the point where the installer does in fact run the script with this:

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

<CustomAction Id="RunStartScript" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Return="check" Impersonate="yes" />
<InstallExecuteSequence>
      <Custom Action="RunStartScript" Before="InstallFinalize">NOT Installed OR UPGRADINGPRODUCTCODE</Custom>
</InstallExecuteSequence>

However, the msi fails with this error:

The script 'Start.ps1' cannot be run because it contains a "#requires" statement for running as Administrator. The current Windows PowerShell session is not running as Administrator. Start Windows PowerShell by using the Run as Administrator option, and then try running the script again.

The installer already prompts for an Administrator before install begins, so I assumed the PowerShell command would be running as an admin already, this must not be the case.

I've found some answers that involve adding code to the start of a script to check for Admin privileges and to pass the command and args along to an Admin session, but I was looking for the possibility of another option as this is a signed script that someone else provided so any changes to it would have to go back to them for re-signing.

1 Answer 1

6

Needed to change Impersonate="yes" to Impersonate="no" so that the Powershell session wasn't ran as the normal user.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.