Search code examples
.netvb.netargument-passingfile-association

Open application and pass arguments from hyper-link in email


This is all done internally with trusted/full access.

How can I open my application from a hyper-link in an email and pass arguments?

I understand I can set up a file/link type association (although I'm unsure how to do this programmatically or during installation). Is this the best approach and/or how would I set this up?

I could pass arguments when opening the application (seems a bit of a hacky way to do this though) but this wouldn't work when the application is already open (single instance only), which will more than likely always be the case.

I've seen some stuff done with JavaScript / ActiveX but as these links will always be in an email in Outlook I don't that approach would work.

All the machines are using Windows 7 and .Net 4.1


Solution

  • See the control panel item "Default Programs" and then "Set Associations" ( "Make a file type or protocol (such as.mp3 or http://) always open in a specific program" )

    These are set through registry keys (which can be done with an installer). You get through the entire url as your first argument, so you will need to pick this apart.

    See the docs:

    http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx

    There are examples of the registry keys and a simple demo program.

    For reference, the registry key is structured like this:

    HKEY_CLASSES_ROOT 
       myapp
          (Default) = "URL:MyApp Protocol"
          URL Protocol = ""
          DefaultIcon
               (Default) = "myapp.exe,1"
          shell
               open
                    command
                         (Default) = "C:\Program Files\WunderWurks\myapp.exe" "%1"
    

    Once you've set that up, you can add a normal HTML link to your app, like <a href="myapp:one_two_three">Click here</a>

    And your app will get called like myapp.exe one_two_three