[Translation] register an application as a URL protocol (registering an application to a URL protocol)

Source: Internet
Author: User
Tags key string

Registering an application to a URL protocol (http://msdn2.microsoft.com/en-us/library/aa767914.aspx)

ArticleAbout asynchronous pluggable protocols describes how to develop and process a new protocol.Program(Processor handlers ). In some cases, we may describe how to call another application to process custom protocols ). Register an existing application as a URL protocol processor. Once the application is successfully started, we can use the command line parameters to retrieve the URL to start it.

    • Register an application to process custom protocols
    • Start the Handler
    • Example
    • Related Topics

Register an application to process custom protocols

You must add a new key and related values to hkey_classes_root so that the application can process special URL protocols.

The newly registered key must match the Protocol scheme before it can be added. For example, to add an "alert:" protocol, the key added to hkey_classes_root must beAlert. Under the new key, the default string value will display the name of the new protocol, and the URL protocol string value will contain protocol-specific information or empty strings. Keys will also be addedDefaulticonAndShell.

The default defaulticon key string value must be the path of the new URL protocol icon file name. (1: defaulticon key)

InShellUnder a key, a key is added using a verb (like open. OneCommand)Key and oneDdeexec (Dynamic Data Exchange execution)Keys are added using verbs. The values after command and ddeexec keys are used to call (or start) the application to process the new protocol.

 

Start the Handler

After a user clicks a link that registers your custom URL protocol, Windows Internet Explorer (IE) starts the registered URL protocol processor. If the shellopen command is specified to include a % 1 parameter in the registry, Internet Explorer passes the URI to the processor of the registration protocol. This final unified Resource Identifier (URI) is encoded (% 1); that is, the hexadecimal character is converted to an equivalent UTF-16 character. For example, replace spaces with % 20 strings.

Security Warning: The application must fully handle malicious data when processing URL protocols. Because the handler receives data from untrusted sources, the URL and other parameter values are passed to the malicious data that the application may contain in an attempt to use the handler. Therefore, the handler can first start idle Behaviors Based on external data to confirm these behaviors and their users.

Note: In addition, the handler will be able to process URLs that may be too long or contain unexpected (or redundant) strings. For more information, see writing secure code.

 

Example

The following example demonstrates how to register the alert.exe application to handle the alert protocol.

Hkey_classes_rootalert(Default) ="URL: alert protocol"URL protocol =""Defaulticon(Default) ="Alert.exe"Shellopencommand(Default) ="C: \ Program Files \ alert \ alert.exe""% 1"
 
Add these settings to the registry, and try to navigate to a URL like "alert: hello000020world.pdf". We will try to start the alert.exe program and pass "Hello World" in the command line"

The followingCodeA simple C # console application is included to demonstrate a way to implement the alert protocol handler.

 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 ();}}}
 
 

Related Topics

  • About asynchronous pluggable protocols
  • Debugging tips

     

    Annotation

    2. Detailed steps:

    1. Compile the console program as shown above and record the full path of the exe;
    2. Start-> Run-> enter Regedit to start Registry Editor ";
    3. Find the (usually the first) hkey_classes_root node, right-click the new item, and enter the expected protocol name, such as gocool;
    4. Similarly, the following hierarchical structure is created:
    5. Run the following command in the browser:

    It is worth noting that the parameter will start with "," by default, but it doesn't matter. We can get all the URL strings. For us, other content is a bit of old-fashioned. This "," is the one in the Command setting "...... The comma in "," % 1. You can also use the statement "C: \ gocoolcenter \ mycsharpproject \ consoleapplication \ ca_registeringhandlingcustomprotocol \ bin \ debug \ logs" % 1 "to replace the previous statement. Remove the quotation marks on both sides of "" % 1 "". The subsequent parameters are output with spaces separated.

  • 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.