c# - 如何从 Windows 商店应用程序启动桌面应用程序?

标签 c# windows windows-store-apps microsoft-metro windows-8.1

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

任何帮助将不胜感激。提前致谢!

最佳答案

如评论中所述,由于沙盒环境,您无法直接从 Windows 应用商店应用程序启动可执行文件。但是,您可以使用 launcher用于启动与文件关联的可执行文件的 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
   }
}

关于c# - 如何从 Windows 商店应用程序启动桌面应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31339097/

相关文章:

java - C# IEnumerable 相当于 java Iterator 的 next() 方法?

javascript - 为 Angular 图创建动态对象

c# - 使用 C# 在 WinRT 中获取可用磁盘空间

c# - 使用 Viewbox 扩展 C# XAML 的优点/缺点

windows - 将 node-webkit 应用程序打包为 ".appx"(适用于 Windows 8 商店)

c# - 反射不触发参数化构造函数c#

c# - LinQ to SQL 查询数据库并分配给当前实例(此)

c - 如何在C中最小化到系统托盘

windows - NHibernate.InstantiationException 无法加载测试类型 : <Foo>

windows - graphviz/dot崩溃(结果是由于安装错误引起的)