![](/img/trans.png)
[英]Process with Verb = “runas” does not start with the credentials defined in Arguments
[英]Child process of WiX CustomAction ignores -Verb runAs
我有一个需要在管理员权限下运行 PowerShell 脚本的 WiX CustomAction。 在 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);
该脚本需要管理员权限才能运行(使用#Requires -RunAsAdministrator
)。
在提示用户允许安装程序对机器进行更改后,将执行此自定义操作。 即之后=“InstallInitialize”。
请有人建议我如何解决这个问题。 例子会很棒。
自定义操作必须已经提升运行。 这是通过将其调度为没有模拟的延迟自定义操作并在 InstallInitialize 和 InstallFinalize 之间的 InstallationExecuteSequence 中调度来实现的。
此外,c#/.net 可以创建一个 powershell 管道,以便您可以加载脚本并执行它。 这使您可以更好地控制错误处理并能够记录到安装程序日志。 否则,如果您真正想要做的只是掏空而没有别的,您可以使用 WiX Quiet Execute 自定义操作模式,它会为您完成所有这些并将输出捕获到 MSI 日志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.