![](/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.