簡體   English   中英

UWP 不想以管理員身份執行進程

[英]UWP don't want to execute process as admin

我有代碼:

// Execute msi
Process process = new Process();
process.StartInfo.FileName = "msiexec";
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(msiPath);
process.StartInfo.Arguments = $"  /passive /i {Path.GetFileName(msiPath)}";
process.StartInfo.Verb = "runas";
process.StartInfo.UseShellExecute = true;
process.Start();
process.WaitForExit();

但我有錯誤:

此平台不支持 UseShellExecute。

或者如果我禁用 UseShellExecute

process.StartInfo.UseShellExecute = false;

由於管理員權限,程序無法執行

Sooo...如何在 UWP 中以管理員身份執行 msi?

首先,這里-提到ProcessStartInfo.UseShellExecute物業稱定,如果你在UWP應用程序做的ProcessStartInfo.UseShellExecute屬性將引發PlatformNotSupportedException。 你得到的行為是預期的。 其次,UWP 應用不支持Process.Start 方法 要從您的 UWP 應用程序運行 exe 文件,我建議您使用FullTrustProcessLauncher Class

首先,您需要復制exe文件並將其保存在UWP應用程序包中,例如Assets文件夾。 然后請前往 Manifest 文件並添加runFullTrust 受限功能。( App 功能)。 接下來,為 UWP 項目添加Windows Desktop Extensions的引用。 最后,您可以調用await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(); 從您的應用程序啟動 exe 文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM