[go] Custom URL Protocol Handler, calling EXE program from Web page

Source: Internet
Author: User

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!

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.