我试图从c#控制台应用程序启动UWP应用程序。它尝试使用使用APPID的以下代码
Process.Start(@“ C:\ Program Files(x86)\ Windows Kits \ 10 \ App Certification Kit \ microsoft.windows.softwarelogo.appxlauncher.exe”,“ 1a75-6f75-5ed3-8944-6b7df2bee095”) ;
是否有更好的方法以编程方式启动UWP应用程序。
答案 0 :(得分:0)
要在系统上启动任何UWP应用,可以使用以下API:
AppListEntry.LaunchAsync Method
要获取所需应用程序的AppListEntry,请使用PackageManager API:
PackageManager.FindPackageForUser(String, String) Method
Package.GetAppListEntriesAsync Method
或者,您可以使用以下Win32 API代替AppListEntry API:
IApplicationActivationManager::ActivateApplication method
答案 1 :(得分:0)
我试图通过协议启动UWP应用。以下链接将帮助您创建协议
Automate launching Windows 10 UWP apps
现在您可以使用
启动应用程序Process.Start(“ URL:myapplication://”);
该进程类在System.Diagnostics中可用。并且还需要在App.xaml.cs文件中添加以下方法
protected override void OnActivated(IActivatedEventArgs args)
{
Initialize(args);
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
// Always navigate for a protocol launch
rootFrame.Navigate(typeof(MainPage), eventArgs.Uri.AbsoluteUri);
// Ensure the current window is active
Window.Current.Activate();
}
}
答案 2 :(得分:0)
当您的控制台应用程序是用一些外来语言编写时,例如 Java,您可以执行类似的操作
https://www.c-sharpcorner.com/article/launch-uwp-app-via-commandline/ 为了获得更好的结果,请省略这两个属性:
<!-- Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$"-->
然后继续as described here。