Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registering an Application to a URI Scheme in windows 10

A few years back I developed a Silverlight Component called from within an ASP.net web app, that uses PInvoke to access a USB (Serial COM port) on the client machine to allow for sending commands to some scanner hardware.

With the advent of Windows 10 and the inevitable demise of Silverlight I am looking for alternatives to accessing hardware on the client PC (This is all Intranet Web Application stuff where we have a lot of control over the implementation)

Currently I am looking at Registering an Application to a URI Scheme (Easy solution) as per this page:https://msdn.microsoft.com/library/aa767914(v=vs.85).aspx OR alternatively maybe Javascript navigator.msLaunchUri (This seems to not be supported in Windows 7, which we need to still support) Refer: https://connect.microsoft.com/IE/feedback/details/864863/documented-api-function-navigator-mslaunchuri-not-present-in-windows-7

The Registering of an Application to a URI Scheme works fine in Windows 7/8/8.1 but seems to have changed in Windows 10 - Does anyone know how I can implement this (Through C# code, registry, something) to allow this to work in Windows 10

like image 951
BFG Avatar asked Sep 21 '15 11:09

BFG


People also ask

What is an app URI?

Just like a URL is an address for a website, a URI is the address for an app on a mobile device.

How can I get URI for job application?

An easy way to obtain the proper URI for an Android app is to visit the app's page in the Google Play Store, tap the share button, and paste the copied link somewhere you can read it. The link will look like https://play.google.com/store/apps/details?id=com.twitter.android.

How do I register an application in Windows Registry?

An application that is installed for per user can be registered under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths. An application that is installed for all users of the computer can be registered under HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths.

What is custom URI scheme?

Overview. Custom URL schemes provide a way to reference resources inside your app. Users tapping a custom URL in an email, for example, launch your app in a specified context. Other apps can also trigger your app to launch with specific context data; for example, a photo library app might display a specified image.


1 Answers

I recently wanted to just this as well - and I found the answer so i'm posting it here for future reference and I couldn't find a working example in C# anywhere.

First of all your app needs requireAdministrator permissions. To do this, right click on the project in the Solution Explorer and click Add New Item, then select General and finally Application Manifest file if you don't already have one. In there, change the requestedExecutionLevel to requireAdministrator. Save.

I this is the first time you've done this, you'll need to restart Visual Studio as it probably isnt running under Admin privaleges.

Okay, so I wanted my app to create the registry key when it starts up, so in the constructor for my form I put in the following code, which creates the URL Protocol foo:// for a program called 'oggsplit.exe' (which I happened to have in my C: root so I just used that for testing)

RegistryKey key;
key = Registry.ClassesRoot.CreateSubKey("foo");
key.SetValue("", "URL: Foo Protocol");
key.SetValue("URL Protocol","");

key = key.CreateSubKey("shell");
key = key.CreateSubKey("open");
key = key.CreateSubKey("command");
key.SetValue("", "C:\\oggsplit.exe");

Once you've configured that, save and run the program. You'll get no feedback, and as long as you don't see any errors it should have worked correctly. Now, open your browser (no need to restart or anything) and go to the address foo://hello. This is what it looks like for me in Google Chrome: enter image description here

It will then ask you if you want to open your application from the browser, click okay. Hey Presto, your app opens from the browser, you can now put a specilised link into your web page to open your app from the browser. This Page also documents how to pass arguments through to your program as well.

like image 144
Chud37 Avatar answered Nov 05 '22 04:11

Chud37