【问题标题】:Using Command Line args with Windows.System.Launcher.LaunchFileAsync in a uwp app在 uwp 应用程序中使用带有 Windows.System.Launcher.LaunchFileAsync 的命令行参数
【发布时间】:2020-01-30 16:46:22
【问题描述】:

我正在使用以下代码从我的 uwp 应用程序启动一个 powerpoint 文件:

Windows.System.Launcher.LaunchFileAsync("MyPath\powerpointFile.ppt");

这绝对没问题。

我现在想为这个方法提供一些命令行参数,但是看着documentation,我看不到任何命令行参数的提及。

是否可以在 uwp 应用程序中使用 Launcher 打开文件并将命令行参数传递给它

我的桌面应用程序当前打开 powerpoint 文件如下:

  ProcessStartInfo startInfo = new ProcessStartInfo();
  startInfo.FileName = "POWERPNT.exe";
  startInfo.Arguments = "/S " + "\"" + fileName + "\"";
  var process = Process.Start(startInfo);

【问题讨论】:

  • 您想使用哪些命令行参数?您可以尝试将Office URI scheme 传递给LaunchUriAsync 方法。
  • 我希望在 kiosk 模式下启动 powerpoint - 或在桌面上使用 /s 参数

标签: c# uwp


【解决方案1】:

我设法通过创建自定义 URI 处理程序(单独的 c# 程序)并将其与我的 uwp 应用程序一起部署来解决这个问题。

读取的代码:

 if (args[0].StartsWith("myProg:Open",true, CultureInfo.CurrentCulture))
 {
     var split = args[0].Split(';');

     var argsString = split[1];

     var progArgs = argsString.Split('~');

      var program = progArgs[0];
      List<string> commandLineArgs = new List<string>();
      for (int i = 1; i < progArgs.Count(); i++)
      {
          commandLineArgs.Add(progArgs[i]);
      }

      ProcessStartInfo startInfo = new ProcessStartInfo();
      startInfo.FileName = program;
      startInfo.Arguments = string.Join(" ", commandLineArgs);
      var process = Process.Start(startInfo);

      return;

}

你可以这样称呼它:

Windows.System.Launcher.LaunchFileAsync("myprog:Open;POWERPNT.exe~/S~\"MyPath\powerpointFile.ppt\"")

更新

另一种方法是查看使用broadFileSystemAccess (https://www.dotnetapp.com/?p=438)

可以使用此链接中的信息来实现:broadFileSystemAccess UWP

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-13
    • 2021-04-30
    • 2018-06-12
    • 2021-11-26
    • 2018-05-14
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    相关资源
    最近更新 更多