【发布时间】:2021-07-05 07:06:39
【问题描述】:
我有代码:
// 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?
【问题讨论】:
-
@ChrisBerlin 我不同意你的观点。对于菜单中的某些 UWP 应用程序,我可以单击“以管理员身份运行”。如果我不能动态请求权限,理论上我可以使用管理员权限启动应用程序。但我不知道 - 如何在实践中做到这一点
-
请查看 Chris Berlin 发布的 API 文档,其中明确提到如果您在 UWP 应用程序中设置 ProcessStartInfo.UseShellExecute 属性将引发 PlatformNotSupportedException。你得到的行为是预期的。
-
另一件事是您无法从 UWP 应用程序执行 msi。请在 WPF 或 Win32 应用上试用。
-
您不能直接从 UWP 执行此操作 - 您必须在同一个安装文件夹中设置不同的 exe 才能通过此处概述的解决方法:stackoverflow.com/questions/49189353/…
标签: c# uwp process shellexecute