How to launch .exe file in uwp app using fulltrustlauncher?

梦想的初衷 提交于 2019-11-29 02:40:14

Finally, I can launch my .exe file in my UWP Application. I will describe my workaround step by step like this:
1. Create your executable .exe file (for example console application)
2. copy .exe file to your UWP Application start up folder (for example: Assets folder)
3. In UWP App Solution Explorer, add reference to "Windows Desktop Extensions For The UWP v10.0.14393.0"(or higher) under "References > Universal Windows > Extensions".
4. In UWP App Solution Explorer, open Package.appxmanifest xml file (right click on Package.appxmanifest file --> view code). add these namespace

xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"

to Package tag. And then, add this extension:

<Extensions>
    <desktop:Extension Category="windows.fullTrustProcess" Executable="Assets\YourExecutableFileName.exe" />
</Extensions>

under Application tag. And then, add this code:

<rescap:Capability Name="runFullTrust" />

into your Capabilities tag. this step mean: talk to compiler to know that it shuld trust your .exe file in the Assets\YourExecutableFileName.exe location.
5. In your UWP Application whenever you want to launch the .exe file, you need to execute this code:

await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();

reference:Great answer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!