3

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

GJKH
  • 1,715
  • 13
  • 30
  • Is this application installed in a server ?? , what do this application do ?? – Amarnath R Shenoy Mar 10 '14 at 11:38
  • @AmarnathRShenoy it's a desktop LOB app, my idea is to use links in automated email alerts to open reports or link to customer accounts. – GJKH Mar 12 '14 at 00:57
  • i tried a lot of different combinations and nothing seemed to have worked, the only way i could get it to work, is to create shortcuts off your application with the arguments already set up, then hyperlink to these shortcuts instead of directly to the application. – Frank_Vr Mar 17 '14 at 00:09

2 Answers2

4

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

Iain Ballard
  • 4,433
  • 34
  • 39
  • Thank you for this, at least now I know how to set this up at installation - my concern is that this will try to launch another instance of the application if it is already open? – GJKH Mar 12 '14 at 01:01
  • 1
    Yes, it will. In which case, you need to handle that in your application. See ( http://stackoverflow.com/questions/1207105/restrict-multiple-instances-of-an-application ) or (http://stackoverflow.com/questions/19147/what-is-the-correct-way-to-create-a-single-instance-application); HOWEVER, you risk disrupting a user's existing workflow in an unexpected way. It may be better to structure your program in a way that makes having two instances workable. – Iain Ballard Mar 12 '14 at 08:48
  • Sorry for the delay in replying, have been poorly. I think this is the best approach, instead of making a single instance app manually handling it myself. Interrupting workflow isn't a real problem as the app is a tab based so no existing work would be lost and as the user clicked the link I would hope they understand what is happening. Thanks for your help!. – GJKH Mar 18 '14 at 18:04
  • I was unable to get this to work. I added the Registry Keys, and the hyperlink was able to open up the application, but it didn't accept the argument. Has anyone else experienced this? Or is there something I'm missing? – John Grabanski Sep 19 '16 at 13:35
0

by using vb script (if you are able to) - you can use this code:

    <script type="text/vbscript" language="vbscript">

    sub testing

     Set wshShell = CreateObject ("WSCript.shell")
     wshshell.run "c:\path\programName.exe arg1 arg2 .... argn"
     set wshshell = nothing

    end sub

    </script>
ayheber
  • 261
  • 3
  • 9
  • I don't think I can use this as a link in an email - I could attach a vbs perhaps but that's pretty clunky and I'm not comfortable with telling people it's ok to open *.vbs attachments (assuming the anti virus doesn't just block it immediately). Also this won't work when the application is already running, it will try to open another instance which is forbidden. – GJKH Mar 05 '14 at 15:05
  • about that - you are right. thats exactly why I wrote "If you are able to". – ayheber Mar 05 '14 at 15:15
  • In which case you didn't read the question: Open application and pass arguments from "hyper-link in email" – GJKH Mar 05 '14 at 15:42