如何从windows应用商店启动桌面应用程序

本文关键字:启动 桌面 应用程序 应用 windows | 更新日期: 2023-09-27 18:02:07

请告诉我如何使用c#从Windows商店应用程序启动桌面应用程序或。exe文件。

任何帮助都将非常感激。提前感谢!

如何从windows应用商店启动桌面应用程序

正如评论中所说,由于沙盒环境,你不能直接从Windows Store应用程序启动可执行文件。但是,您可以使用启动器API来启动与文件关联的可执行文件。因此,可以在自定义文件扩展名和要启动的应用程序之间创建文件关联。然后,只需使用启动器API打开具有自定义文件扩展名的文件。

public async void DefaultLaunch()
{
   // Path to the file in the app package to launch
   string imageFile = @"images'test.png";
   var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
   if (file != null)
   {
      // Launch the retrieved file
      var success = await Windows.System.Launcher.LaunchFileAsync(file);
      if (success)
      {
         // File launched
      }
      else
      {
         // File launch failed
      }
   }
   else
   {
      // Could not find file
   }
}