Search code examples
c#winapiuwpargumentsactivation

How do you implement Launching a win32 exe with command line arguments from an UWP app?


I am trying to launch a legacy win32 software that takes command line arguments from my UWP app.

The win32 app (xxx) does not inherently support activation protocols and URI but I was able to add this by using registry entries at:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\xxx]
@="URL:xxx"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\xxx\shell]

[HKEY_CLASSES_ROOT\xxx\shell\open]
@=""

[HKEY_CLASSES_ROOT\xxx\shell\open\command]
@="\"C:\\Program Files (x86)\\xxx\\xxx.exe\" \"%1\""

I have implemented the following in my UWP app but it only launches the app and does not pass the arguments:

 await Launcher.LaunchUriAsync(new Uri("xxx:aaa=123"));

How do I go about passing command line arguments to a Win32 app from UWP?

I don't mind creating a Win32 app or a console app to be the middle man here to read the activation protocol and convert it to a command line argument and run the win32 but could not find any solutions to doing so.

Thanks.


Solution

  • I tried xxx:\aaa=123. However, it passes the argument (%1) as a whole including the protocol. How do I remove or replace the xxx:\ from %1

    And please check @="\"C:\\Program Files (x86)\\xxx\\xxx.exe\" \"%1\"", it contain %1 as default. You could remove it manually.