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!