【问题标题】:How to launch a desktop application from windows store apps?如何从 Windows 商店应用程序启动桌面应用程序?
【发布时间】:2015-09-29 02:30:03
【问题描述】:

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

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

【问题讨论】:

  • Process.Start 怎么样?
  • 这不是不可能的。而且问题看起来与stackoverflow.com/questions/17969019/… 重复
  • @Herdo 此命名空间在 Windows 应用商店应用中不可用
  • @feeeper 你的意思是不能从 Windows Store 应用调用外部程序?
  • @WaqasAhmedKhan 是的。因为windows store应用是在沙盒环境下运行的。

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


【解决方案1】:

如 cmets 中所述,由于沙盒环境,您无法直接从 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
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多