Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 812
GIANGPZO Avatar asked Jan 03 '23 13:01

GIANGPZO


2 Answers

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

like image 138
GIANGPZO Avatar answered Mar 17 '23 03:03

GIANGPZO


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://learn.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

like image 28
Stefan Wick MSFT Avatar answered Mar 17 '23 01:03

Stefan Wick MSFT