简体   繁体   English

如何在 UWP 中运行 PowerShell 命令?

[英]How to run a PowerShell command in UWP?

How to run a PowerShell command in UWP?如何在 UWP 中运行 PowerShell 命令?

using (PowerShell PowerShellInstance = PowerShell.Create())
{
    PowerShellInstance.AddCommand(".\fpcalc.exe " + file.Path + " > out.txt");
}

Because UWP apps run in a sandbox, you cannot directly execute another processes or run PowerShell scripts.由于 UWP 应用在沙箱中运行,因此您无法直接执行其他进程或运行 PowerShell 脚本。 However, you can utilize Windows.ApplicationModel.FullTrustProcessLauncher if you declare such capability in your app to launch a full trust process (like a console application) which can safely execute such script.但是,如果您在应用程序中声明此类功能以启动可以安全执行此类脚本的完全信任进程(如控制台应用程序),则可以利用Windows.ApplicationModel.FullTrustProcessLauncher

You need to add a restricted fullTrust capability to your app's Package.appxmanifest .您需要向应用程序的Package.appxmanifest添加受限的fullTrust功能。

You can learn more about full trust processes in UWP from documentation , UWP samples or blogposts like the excellent blogpost series from Stefan Wick.您可以从文档UWP 示例或博客文章(如 Stefan Wick 的优秀博客文章系列)中了解有关 UWP 中完全信任流程的更多信息。

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

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