简体   繁体   中英

How to run a PowerShell command in UWP?

How to run a PowerShell command in UWP?

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. 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.

You need to add a restricted fullTrust capability to your app's Package.appxmanifest .

You can learn more about full trust processes in UWP from documentation , UWP samples or blogposts like the excellent blogpost series from Stefan Wick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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