Go Windows Registry Custom Protocol

Source: Internet
Author: User
Tags key string

[Turn from] http://blog.sina.com.cn/s/blog_86e4a51c01010nik.html

1. Registering the application to process the custom protocol

You must add a new key along with the associated value to HKEY_CLASSES_ROOT so that the application can handle the special URL protocol.

The newly registered key must match the protocol scheme before it can be added. For example, to add an "alert:" Protocol, the key that is added to HKEY_CLASSES_ROOT must be alert. Under this new key, the default string value will display the name of the new protocol, and the URL protocol string value will contain the protocol-specific information or an empty string. The keys will also be added to the DefaultIcon and shell.

The default DefaultIcon key string value must be the path to the new URL protocol icon file name.

Under Shell Key, a key uses a verb (like open) to be added. a command (command) key and a ddeexec (Dynamic data exchange execution) key are all added using verbs. This command and the values after ddeexec keys are used to invoke (or start) the application that processes the new protocol.

2, start the processing program

When a user clicks on a link that is registered with your custom URL protocol, Windows Internet Explorer (IE) initiates the registration of the processor for the URL protocol. If the Specify Shellopen command contains a%1 parameter in the registry, Internet Explorer passes this URI to the processor of the registration protocol. This last Uniform Resource Identifier (URI) is encoded (% 1); that is, the 16-bit code-break is converted to an equivalent UTF-16 character. For example, use the%20 string instead of a space.

Security Warning: Application processing URL protocol must be fully exposed to malicious data. Because handlers receive data from untrusted sources, URLs and other parameter values are passed to the application that may contain malicious data that attempts to use handlers. Therefore, the handler can first initiate an idle behavior based on external data to confirm these behaviors and their users.

3. Example

The next example shows how to register the Alert.exe application to handle the alert protocol.

Reference content

Windows Registry Editor Version 5.00

[Hkey_classes_root\alert]

@= "Url:alert Protocol"

"URL Protocol" = "C:\Program Files\alert\alert.exe"

[Hkey_classes_root\alert\defaulticon]

@= "C:\Program files\alert\alert.exe,1"

[Hkey_classes_root\alert\shell]

[Hkey_classes_root\alert\shell\open]

[Hkey_classes_root\alert\shell\open\command]

@= "C:\Program files\alert\alert.exe" "%1"

Adding these settings information to the registry, attempting to navigate to URLs like "Alert:hello%20world" will attempt to start the Alert.exe program and pass "Hello World" on the command line.

4. Protocol Processing Example

The following code contains a simple C # console application that demonstrates how to implement the alert protocol handler: Copy content to Clipboard program code

Using System;

Using System.Collections.Generic;

Using System.Text;

Namespace Alert1

{

Class Program

{

static string ProcessInput (string s)

{

TODO Verify and validate the input

string as appropriate for your application.

return s;

}

static void Main (string[] args)

{

Console.WriteLine ("Alert.exe invoked with the following parameters.\r\n");

Console.WriteLine ("Raw Command-Line: \n\t" + environment.commandline);

Console.WriteLine ("\n\narguments:\n");

foreach (string s in args)

{

Console.WriteLine ("\ T" + processinput (s));

}

Console.WriteLine ("\npress any key to continue ...");

Console.readkey ();

}

}

}

Go Windows Registry Custom Protocol

Related Article

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.