简体   繁体   中英

Child process of WiX CustomAction ignores -Verb runAs

I have a WiX CustomAction that needs to run a PowerShell script under admin privileges. In C# the obvious way to do this would be as follows:


                var startInfo = new ProcessStartInfo
                {
                    FileName = "powershell.exe",
                    Arguments = $"-File myscript.ps1",
                    Verb = "runAs",
                    UseShellExecute = false,
                    CreateNoWindow = true,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true
                };

                var process = Process.Start(startInfo);

The script requires admin privileges to run (using #Requires -RunAsAdministrator ).

This custom action is performed after a user is prompted to allow the installer to make changes to the machine. Ie After="InstallInitialize".

Please can someone suggest how I can resolve this issue. Examples would be great.

The custom action has to already be running elevated. This is achieved by scheduling it as a deferred custom action with no impersonation and scheduled in the InstallationExecuteSequence between InstallInitialize and InstallFinalize.

Also c#/.net can create a powershell pipeline so you can load the script and execute it. This gives you better control over error handling and the ability to log to the installer log. Otherwise if all you really want to do is just shell out and nothing else you can use the WiX Quiet Execute custom action pattern and it will do all this for you and capture the output to the MSI log.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM