0

I've already read and researched all over the net including here: Windows Universal Apps: Call python method from C# [closed]

And I understand that UWP is a sandbox and can't open other processes. Nonetheless, I got no other choice but to use python API inside UWP app. The answer in the link above is not clear enough for me and I hope to get any solution, even if it's not a direct one.

Of course I tried IronPython which is not working. And Process/ProcessInfo which brigs-up "access denied". Azure is also not an option.

Thanks.

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51
Izik
  • 746
  • 1
  • 9
  • 25

1 Answers1

2

If your app is intended to run on the Python script only on PC (and not on phones, HoloLens, xbox, etc.) then you can use an API from the UWP desktop extension SDK:

FullTrustProcessLauncher

This API allows you to launch regular full trust EXEs that are included in your app package from your UWP. Those EXEs will then run outside of the appcontainer sandbox and you can execute things like Python scripts (and many more scenarios). When using this API your app can continue to be run on HoloLens etc., but it won't be able to launch those full trust processes on those platforms.

I have a tutorial on this topic on my blog: https://stefanwick.com/2018/04/06/uwp-with-desktop-extension-part-1/

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51
  • 1
    Hi. thanks for your tutorial. But when I'm following instructions I get exception in the line: await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(); The exception is "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))". When trying to use your code in Github I get "Error APPX3217 SDK folder containing 'UAP.props' for 'UAP 10.0.16299.0' cannot be located" – Izik Feb 14 '19 at 14:53
  • Make sure you declare the 'runFullTrust' capability in your appx manifest. In order to load the project from GitHub, make sure you have the SDK v16299 installed, or if you have a later SDK update the project accordingly. – Stefan Wick MSFT Feb 14 '19 at 15:19
  • 1
    Thanks now your example code is working,I will try to see what the problem with mine. – Izik Feb 17 '19 at 17:57
  • Sorry I was wrong, this GitHub code (UWP_FullTrust_1) also bringing "Acces is denied" same exception as mine_______________________________ Also, in the package manifest there is a problem with the tag: _________________________________ "The element "Capabilities" in namespace "http://schemas.microsoft.com/appx/manifest/foundation/windows10" has invalid child element "Capability" in namespace "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities".... – Izik Feb 18 '19 at 11:29
  • That warning about the invalid child element you can ignore. It's a known bug in VS. It will still build and deploy correctly. I just tried the UWP_FullTrust_1 sample again and it works fine on my configuration. Please open a new question about the Access Denied error and include details about your configuration (OS, VS, SDK version etc.). – Stefan Wick MSFT Feb 18 '19 at 14:01
  • I've opened new question in here: [Access is denid...](https://stackoverflow.com/questions/54852168/access-is-denied-in-uwp-c-when-trying-to-run-desktop-extension-app) – Izik Feb 24 '19 at 14:52