title: HTA - Pass parameter from hyperlink to WPF application
body: <p><b>Requirement</b><br>
  I'm trying to use an HTA, or anything at this point, as a go-between between a clicked hyperlink and a WPF application (<code>WPF_App.exe</code>) I have, since we need to send it whatever ID that is on that hyperlink (which will be pre-staged by another application) in order to bring up a particular item within the WPF app.</p>
  
  <p><b>What I've Done</b><br>
  I have the following HTML I've saved as <code>test.hta</code> that can accept a querystring parameter <code>AppID</code> and parse it.  It can then be sent to a WPF application, which is being started using a Wscript.Shell object:</p>
  
  <pre><code>&lt;html&gt;&lt;head&gt;
  &lt;script language="VBScript"&gt;
  Sub RunProgram(param)
      Set objShell = CreateObject("Wscript.Shell")
      objShell.Run "\\our_network_share\some_folder\WPF_App.exe " &amp; param
      Me.Close
  End Sub
  &lt;/script&gt;
  
  &lt;script language ="Javascript"&gt;
  function callVB () {
      var param = getParameterByName('AppID');
      RunProgram(param);
  }
  
  function getParameterByName(name) {
      var url = window.location.href;
      name = name.replace(/[\[\]]/g, "\\$&amp;");
      var regex = new RegExp("[?&amp;]" + name + "(=([^&amp;#]*)|&amp;|#|$)"),
      results = regex.exec(url);
      if (!results) return null;
      if (!results[2]) return '';
      return decodeURIComponent(results[2].replace(/\+/g, " "));
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="javascript:callVB()"&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><b>Problem to Resolve</b><br>
  Even though I can call this HTA using <code>file://our_network_share/some_folder/test.hta?AppID=100</code> in IE or Windows Explorer and it will pass the WPF app the ID correctly, <strong>it will not work from a hyperlink this way</strong> (the link must be created in Outlook using Ctrl+K and use Ctrl+Click to test, since the link will be placed into e-mails... Word is also a good test of this, and also fails, so far), and we need to be able to link to this HTA file from an e-mail while providing a parameter.  Can this be done?  And I'm not locked into this HTA, just it was the closest I've gotten so far.</p>
  
  <p><b>Things I've Tried</b><br>
  I've looked at how you can <a href="https://blogs.technet.microsoft.com/heyscriptingguy/2005/04/20/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts/" rel="nofollow">pass command line arguments to an HTA</a>, but is there a way to pass a parameter from a hyperlink to an HTA in a querystring?  The reason for a querystring is so far I'm not seeing how you can resolve spaces between the HTA file name and the parameter, or the WPF name and parameter for that matter, in a hyperlink.  Putting in the HTML code <code>%20</code> doesn't work, nor does putting quotes around the file link and arguments.  Maybe it's just a syntax issue at this point, but not sure what it would be.</p>