如何使用fulltrustlauncher在uwp应用程序中启动.exe文件?
现在,我需要在我的uwp应用程序中执行.exe文件。我知道一个解决方案是使用fulltrustlauncher,但我已经搜索了很多次这个解决方案,但我的编程水平似乎太低,所以我很难理解他们的解释(例如:Running an EXE from C# using UWP )。那么,您如何为此解决方案提供简单的示例代码?你可以分享吗?
谢谢!如何使用fulltrustlauncher在uwp应用程序中启动.exe文件?
EXE需要包含在appx包中,并在appxmanifest中声明。还要确保你在appxmanifest中声明了'runFullTrust'功能。这就是你需要的。如果这没有帮助,请提出更详细的问题,以便我们了解到底哪些不适合您。
MSDN文档:
https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/AppServiceBridgeSample
https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/SQLServer
https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/UWP%20Office%20Interop
0123:使用此功能 https://docs.microsoft.com/en-us/uwp/api/Windows.ApplicationModel.FullTrustProcessLauncherGitHub的样本
https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/UWP%20Systray
最后,我可以在我的UWP应用程序中启动我的.exe文件。我将逐步描述我的解决方法:
1.创建您的可执行文件(例如控制台应用程序)
2.将.exe文件复制到您的UWP应用程序启动文件夹(例如:Assets文件夹)
3.在UWP App Solution Explorer中,在“参考>通用Windows>扩展”下添加对“Windows桌面扩展UWP v10.0.14393.0”(或更高版本)的引用。
4.在UWP App Solution Explorer中,打开Package.appxmanifest xml文件(右键单击Package.appxmanifest文件 - >查看代码)。这些命名空间
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
添加到包标签。然后,添加此扩展:
<Extensions>
<desktop:Extension Category="windows.fullTrustProcess" Executable="Assets\YourExecutableFileName.exe" />
</Extensions>
下应用标签。然后,添加以下代码:
<rescap:Capability Name="runFullTrust" />
到您的能力标签。这一步的意思是:与编译器交谈,以便知道它信任您的.exe文件的Assets \ YourExecutableFileName.exe位置。
5.在UWP应用程序时,你要启动的.exe文件,你需要执行以下代码:
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
参考:Great answer
非常感谢您的帮助,你的榜样是很很有帮助。 – GIANGPZO