7

Is it possible for a UWP app to launch its Desktop Bridge (full-trust application component) with arbitrary command-line arguments? I see the ability to specify "argument groups" (see https://docs.microsoft.com/en-us/uwp/api/Windows.ApplicationModel.FullTrustProcessLauncher), but it looks like that only supports using a predefined ParameterGroup. I need to launch a UWP with programmatically-determined (at launch time) arbitrary command-line arguments. Is this possible, and if so, how?

Stefan Wick MSFT
  • 12,864
  • 1
  • 26
  • 47
CBHacking
  • 1,673
  • 12
  • 19

2 Answers2

11

No this is not possible today.

One quick way to accomplish the scenario is to have the UWP write the command string to the local app data/settings, which is shared between the two processes. So the full-trust process can then pick up the command string after its been launched from there.

A more complex solution is to establish an app service connection between the two processes, and pass the command string via that connection. This will be helpful if you need to keep communicating back and forth between the two processes.

If for some reason you can't change your existing full-trust process code, you could add an extra EXE to your package that just reads the command string from the app data and then launches your actual full-trust EXE with those parameters (using Process.Start() or something equivalent).

EDIT I have posted some more details and an example on my blog: https://stefanwick.com/2018/04/06/uwp-with-desktop-extension-part-2/

Stefan Wick MSFT
  • 12,864
  • 1
  • 26
  • 47
  • Process.Start() won't work in Windows 10 S which means any UWP app using it won't be accepted into the MSFT App Store. – rfreytag Dec 15 '17 at 17:36
  • 1
    This is not correct. Process.Start() works fine on Windows 10S, as long the EXE comes with your package. Your app will be accepted in the Microsoft Store. – Stefan Wick MSFT Dec 15 '17 at 19:46
  • Can you please elaborate on `write the command string to the local app data/settings`? What exactly do you mean by that? Perhaps a line of code? – ispiro Mar 12 '18 at 22:10
  • 1
    What I meant is to write the command string using the below API from your UWP before launching the process and then picking it up in the full trust process using the same API (as both processes operate on the same local appdata): https://docs.microsoft.com/en-us/windows/uwp/design/app-settings/store-and-retrieve-app-data – Stefan Wick MSFT Mar 12 '18 at 22:43
  • @StefanWickMSFT Thanks! Perfect. (By the way, I'm not notified of your response unless you `@ispiro` me. But I checked so I saw it.) Thanks again. – ispiro Mar 12 '18 at 22:55
  • I have posted some more details and an example on my blog: https://stefanwick.com/2018/04/06/uwp-with-desktop-extension-part-2/ – Stefan Wick MSFT May 22 '18 at 15:35
2

We cannot pass argument dynamically to the full trust process. However, we can pass it using LocalSettings.

  1. Add the arguments to Local Settings and launch the full trust process: In C++:

    auto settings = Windows::Storage::ApplicationData::Current->LocalSettings; settings->Values->Insert("arg1", "val1"); settings->Values->Insert("arg2", "val2"); // Launch Full trust proc create_task(FullTrustProcessLauncher::LaunchFullTrustProcessForCurrentAppAsync()).then([](task<void> t) {/* ... */});

  2. In the full trust process code,

    auto settings = Windows::Storage::ApplicationData::Current->LocalSettings; auto val1 = settings->Values->Lookup("arg1")->ToString();

vine'th
  • 4,516
  • 2
  • 25
  • 26