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

一世执手 提交于 2019-11-29 10:24:59

问题


for now, i need to execute a .exe file in my uwp app. I know a solution is using fulltrustlauncher, but i have searched for many times for this solution, but my programming level seem too low, so It is very difficult for me to understand their explaination (for example: Running an EXE from C# using UWP ). So, how do you have a simple sample code for this solution? can you sharing?
Thank you!


回答1:


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




回答2:


The EXE needs to be included in the appx package, and declared in the appxmanifest. Also make sure you declare the 'runFullTrust' capability in the appxmanifest. That's all you need. If that doesn't help, please ask a more detailed question, so we understand what exactly doesn't work for you.

MSDN documentation: https://docs.microsoft.com/en-us/uwp/api/Windows.ApplicationModel.FullTrustProcessLauncher

GitHub samples that use this feature:

https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/AppServiceBridgeSample

https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/AppServiceBridgeSample_C%2B%2B

https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/SQLServer

https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/UWP%20Office%20Interop

https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/UWP%20Systray



来源:https://stackoverflow.com/questions/45911755/how-to-launch-exe-file-in-uwp-app-using-fulltrustlauncher

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