Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

windows - URI scheme launching

I've been given a task to create a protocol similar to callto:, that - upon clicking on a link with it - would automatically launch an installed aplication.

I followed the microsoft guide on how a scheme should look like.

My scheme looks like this:

HKEY_CLASSES_ROOT
   slican
       URL Protocol = ""
       DefaultIcon (Default) = "C:UsersOkabeDesktopslicanSlicanP.exe,1"
       shell
            open
                command (Default) = "C:UsersOkabeDesktopslicanSlicanP.exe" "%1""

I thought that was all and tested it with

 <a href="slican:test">test link</a>
 <a href="slican:0049325778421">test telephone link</a>

There was no reaction whatsoever. Internet Explorer asked me if I want to search for a program that can open the content and Chrome responded with nothing, as if I clicked javascript:void(0).

How to get that worked?

Thank you for your help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The registration you show works perfectly fine for me when I try it on Windows 7. The local app I registered in place of SlicanP.exe ran fine when I invoked a slican: URL from the Start | Run menu, and from within the address bar of Windows Explorer. So the registration works.

Do be aware that Internet Explorer runs in a lower integrity security context, so it may not have rights to run local programs. When I tried to click on an HTML link to a slican: URL, or type a slican: URL in the address bar, IE had trouble executing the local app (even after prompting for permission). I had to run IE as an administrator, then the local app ran just fine.

Also, you really should not be creating a HKEY_CLASSES_ROOTslican key directly. Create a HKEY_CURRENT_USERSoftwareClassesslican (current user only) or HKEY_LOCAL_MACHINESoftwareClassesslican (all users) instead. Refer to MSDN for more details:

HKEY_CLASSES_ROOT Key

Merged View of HKEY_CLASSES_ROOT

Update: Since it works in Windows 7, Microsoft probably changed how URL schemes are registered in Windows 8. For instance, phone/store apps use URI activation:

URI activation (XAML).

URI activation (HTML)

The documentation says there are two ways to register a custom URI scheme:

Internet Explorer uses two mechanisms for registering new pluggable protocol handlers. The first method is to register a URI scheme name and its associated application so that all attempts to navigate to a URI using that scheme launch the application (for example, registering applications to handle mailto: or news: URIs). The second method uses the Asynchronous Pluggable Protocols API, which allows you to define new protocols by mapping the URI scheme to a class.

You are doing the first. Try using the second instead.

However, I just noticed that "Asynchronous Pluggable Protocols" is listed on MSDN in the "Legacy APIs" section, and it has the following note:

Third-party protocol implementations won't load in Windows Store apps using JavaScript, or in the Internet Explorer in the new Windows UI.

So it may or may not work in Windows 8.

Update: I just found this:

Guidelines for file types and URIs

In Windows?8, the relationship between apps and the file types they support differs from previous versions of Windows.

Walkthrough: using Windows 8 Custom Protocol Activation

The file type and protocol association model has changed in Windows 8. Apps are no longer able to programmatically set themselves as the default handler for a file type or protocol. Instead, now the user always controls what the default handler is for a file type or protocol.

Your app can use existing protocols for communication, such as mailto, or create a custom protocol. The protocol activation extension enables you to define a custom protocol or register to handle an existing protocol.

Also have a look at this:

Setting mailto: protocol handler programmatically in Windows 8

And this:

Default Programs


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...