Custom URL Protocol Handler

Source: Internet
Author: User
Origin: software such as thunder and donkey can be automatically started after clicking a url in the browser and performing operations. How is this implemented? I google a lot, or found a text http://www.cnblogs.com/hwade/archive/2008/01/08/1029686.html in the garden, this brother like to write traditional Chinese characters, although I learned calligraphy, understand some traditional Chinese characters, but still look uncomfortable.
Ah! The qualification is dull. I haven't seen it clearly for a long time, but the idea is clear, that is, I have to do it on the registry. So google continues to find the http://blogs.gotdotnet.com/noahc/archive/2006/10/19/register-a-custom-url-protocol-handler.aspx unfortunately let me understand.
Let me briefly explain my understanding.

This function can be implemented in three steps. (Register a protocol-handler like xishui: // to click xishui: // hello on the webpage. A dialog box is displayed, showing "hello ")
1. Create a registry according to the following structure:

[Xishui] is created under the [HKEY_CLASSES_ROOT] Primary Key of the Registry.
2. assign values to related keys.

The value of the command item above is c: \ test.exe "% 1". This "% 1" is the parameter passed to test.exe. If we click a link like xishui: // hello, the value of % 1 is the string "xishui: // hello.

Now we write the program test.exe. Our goal is to display the "hello" text in the xishui: // hello link in a dialog box. That is to say, we need to use a regular expression to retrieve the part after "xishui: //" in "xishui: // hello ".

Let's write a console program.

Using System;
Using System. IO;
Using System. Windows. Forms;
Using System. Text. RegularExpressions;

Namespace test
{
Class Program
{
Static void Main (string [] args)
{
String key = Regex. Match (args [0], @ "(? <=: //). +? (? =: |/| \ Z) "). Value;
MessageBox. Show (key );
}
}
}

Let me copy the compiled test.exe file to c: \.
Then I wrote test.html <A href = "xishui: // hello"> xishui: // hello </a>

Then I click this link in the browser. What is the result? You guess

Wow, I actually used test.exe and showed hello!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.