Transferred from: http://www.cnblogs.com/zjneter/archive/2008/01/08/1030066.html
Thunder, Electric Donkey and other software can be clicked in the browser after a URL automatically start, and perform the operation. How can this be achieved?
To achieve this function cage is divided into 3 steps. (We register a xishui://such a protocol-handler, achieve in the Web page click Xishui://hello, Pop up a dialog box, the above shows "Hello")
1 Build the registry according to the following structure
where [Xishui] is built under the [HKEY_CLASSES_ROOT] primary key of the registry.
2 assigning values to related keys
It is noted that the value of the command entry above is C:\test.exe "%1", and this "%1" is a parameter passed to Test.exe. If we click on a link such as Xishui://hello, then the value of%1 is the string "Xishui://hello".
Here we rewrite the program to generate Test.exe, our goal is to pop up a dialog box to display the Xishui://hello link in the Hello Word. Which means we're going to use regular expressions to take out the parts behind "xishui://" in "Xishui://hello".
Let's write a console program.
usingSystem;
usingSystem.IO;
usingSystem.Windows.Forms;
usingSystem.Text.RegularExpressions;
namespaceTest
{
classProgram
{
static void Main (string[] args)
{
string key = regex.match (args[0], @ " (? <=://). +? (? =:|/|\z)"). Value;
MessageBox.Show (key);
}
}
}
Let me copy the compiled generated test.exe to C #
And then I wrote a test.html.
<ahref= "Xishui://hello">Xishui://hello</a>
Then I clicked this link in the browser, what effect? You guess
Really called the test.exe, and it shows Hello!