简体   繁体   English

WiX CustomAction 的子进程忽略 -Verb runAs

[英]Child process of WiX CustomAction ignores -Verb runAs

I have a WiX CustomAction that needs to run a PowerShell script under admin privileges.我有一个需要在管理员权限下运行 PowerShell 脚本的 WiX CustomAction。 In C# the obvious way to do this would be as follows:在 C# 中,这样做的明显方法如下:


                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 ).该脚本需要管理员权限才能运行(使用#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".即之后=“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.这是通过将其调度为没有模拟的延迟自定义操作并在 InstallInitialize 和 InstallFinalize 之间的 InstallationExecuteSequence 中调度来实现的。

Also c#/.net can create a powershell pipeline so you can load the script and execute it.此外,c#/.net 可以创建一个 powershell 管道,以便您可以加载脚本并执行它。 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.否则,如果您真正想要做的只是掏空而没有别的,您可以使用 WiX Quiet Execute 自定义操作模式,它会为您完成所有这些并将输出捕获到 MSI 日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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