• Associating a URL Protocol to your Application

    Published by jcisneros on June 25th, 2010 4:28 pm under .NET

    No Comments

    This is something done by WebPI (wpi://) and many p2p apps that you can do with your own application also: associate a URL protocol to your application. Let’s say you want to use URLs beginning with myapp:// to launch your own application and perform a certain task (i.e. download a file and open it). This is simply done by adding some entries in the registry, the following steps guides you on how to configure your setup project to do this.

    image

    1. Right click on the Setup project of your solution, go to View and select Registry.
    2. Under HKEY_CLASSES_ROOT create a new key and use the name for your protocol, let’s say “myapp“.
    3. Add a new String value and delete the name, now it should appear with the name (Default).
    4. Set the value to “URL:myapp Protocol”.
    5. Add another String value and name it “URL Protocol“. Leave its value blank. The registry view should now look like the following screenshot:
      image
    6. Under the “myapp” key created on step 2, create a new key and named it “shell“.
    7. Under the “shell” key create a new one named “open“.
    8. Under the “open” key create a new one named “command“.
    9. Add a new String value under the “command” key and delete its name to make it the default value.
    10. Set the default value to ““[TARGETDIR]MyApplication.exe” “%1″“. The registry view should now look like the following screenshot:
      image

    That’s all!, each time the user hits a URL with your custom protocol, your application will be executed and will receive the URL. Now you have to parse it and act accordingly.

    Additional reading: Registering an Application to a URL Protocol

    Tags: , ,

  • Leave a comment

    Your email address will not be published.