Calling RegisterUrlScheme
will create a registry entry that will allow us to launch the application using a custom uri scheme.
HKEY_CURRENT_USER\Software\Classes myApp (Default) = "URL:My Application" URL Protocol = "" DefaultIcon (Default) = "C:\Program Files\Example\Example.exe,1" shell open command (Default) = "C:\Program Files\Example\Example.exe" "%1"
With something like this below, we can always ensure that the application is always registered and if launched though the uri scheme, handle it appropriately.
RegisterUrlScheme();
if (args.Length > 0){ if (Uri.TryCreate(args[0], UriKind.Absolute, out var uri) && string.Equals(uri.Scheme, SchemeUrl, StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Just launched with the uri"); }}
This means that we can now click on links like myApp://
and embed the url anywhere. As the result in the c# client is a Uri, we can easily parse query strings and extract any parameters we may need.