0

I am launching a powerpoint file from from my uwp app using the following code:

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

and this works absolutely fine.

I would now like to provide some command line arguments to this method, but looking at the documentation I can't see any mention of command line arguments.

Is it possible to open a file and pass command line arguments to it using Launcher in a uwp application

My desktop application currently opens the powerpoint file like so:

  ProcessStartInfo startInfo = new ProcessStartInfo();
  startInfo.FileName = "POWERPNT.exe";
  startInfo.Arguments = "/S " + "\"" + fileName + "\"";
  var process = Process.Start(startInfo);
JKennedy
  • 18,150
  • 17
  • 114
  • 198
  • What command-line arguments do you want to use? You could try to pass an [Office URI scheme](https://learn.microsoft.com/en-us/office/client-developer/office-uri-schemes) to the [LaunchUriAsync](https://learn.microsoft.com/en-us/windows/uwp/launch-resume/launch-default-app) method. – mm8 Oct 01 '19 at 12:23
  • I was hoping to launch powerpoint in `kiosk` mode - or on desktop with the /s argument – JKennedy Oct 01 '19 at 13:00

1 Answers1

0

I managed to solve this by creating a custom URI handler (seperate c# program) and deploying this along with my uwp application.

The code read:

 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;

}

and you can call it like:

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

UPDATE

Another way would be to look at using broadFileSystemAccess (https://www.dotnetapp.com/?p=438)

which can be implemented using the information from this link: broadFileSystemAccess UWP

JKennedy
  • 18,150
  • 17
  • 114
  • 198