I have a URI that launches a default program and I'm trying to figure out how to launch it from a Windows Form application. All the results on Google are using the Windows Apps API to launch a URI, but I need to do it from a form. How can this be done?
Here is the Apps version:
System.Uri uri = new System.Uri("myprotocl://10.0.0.123");
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
URIs allow you to launch another app to perform a specific task. This topic also provides an overview of the many URI schemes built into Windows. Learn how to register an app to become the default handler for a Uniform Resource Identifier (URI) scheme name.
Windows Forms (WinForms) is a free and open-source graphical (GUI) class library included as a part of Microsoft . NET, . NET Framework or Mono Framework, providing a platform to write client applications for desktop, laptop, and tablet PCs.
The Run key (And alternatively the RunOnce key for running your application once) will run all applications that are in it on startup/when a user logs on. This is the code I use in my applications, and it works great.
Assuming you have a 'handler' registered on your machine for 'myprotocl', you can launch a uri by specifying the uri as the filename of a process.
var url = "myprotocl://10.0.0.123";
var psi = new ProcessStartInfo();
psi.UseShellExecute = true;
psi.FileName = url;
Process.Start(psi);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With