自定义协议从浏览器中启动本地应用程序

来源:互联网 发布:编程来回打括号好烦 编辑:程序博客网 时间:2024/06/06 02:09

1. 需要启动的本地应用程序为:

e:\SRC\Test\MyApp\bin\Debug\MyApp.exe

2.编辑注册表导入文件: MyApp_Disk_D.reg

内容如下:

Windows Registry Editor Version 5.00  [HKEY_CLASSES_ROOT\myapp]  @="URL:AutoHotKey myapp Protocol"  "URL Protocol"=""  [HKEY_CLASSES_ROOT\myapp\DefaultIcon]  @="myapp.exe,1"  [HKEY_CLASSES_ROOT\myapp\shell]  [HKEY_CLASSES_ROOT\myapp\shell\open]  [HKEY_CLASSES_ROOT\myapp\shell\open\command]  @="\"e:\\SRC\\Test\\myapp\\bin\\Debug\\myapp.exe\" \"%1\"" 

3. 将上面的文件导入到注册表.

4. 在IE中输入如下内容,即可启动应用程序myapp.exe

myapp://parameter

5. 至此在大多数浏览器中,已经能够通过自定义的协议启动指定应用程序了.

6. 对于Chrome浏览器,若不能启动指定的应用,请查看如下几点

  1. 自定义协议后的参数不能太短,最好超过三个字符,并且最好不要用一些常用的关键字.
  2. 配置Chrome的阻止的协议列表, 配置文件路径如下,不用的安装路径,还不用的用户,路径稍有不同:
    C:\Users\liu\AppData\Local\Google\Chrome\User Data\Local State
    打开此文件后,找到如下内容:
"protocol_handler":  {      "excluded_schemes":      {          "afp":true,          "data":true,          "disk":true,          "disks":true,          "file":true,          "hcp":true,          "iview":false,          "javascript":true,          "mailto":false,          "ms-help":true,          "ms-windows-store":false,          "myapp":false,          "news":false,          "nntp":true,          "shell":true,          "snews":false,          "tencent":false,          "vbscript":true,          "view-source":true,

确保我们自己定义的协议 myapp 后面的值为”false”, 即不在被排除的列表中.

7. 通过网页中的连接打开本地相关应用程序的示例如下

<!DOCTYPE html>  <html>   <head>      <title>Web Automation</title>      <script type="text/javascript">          function dicom() {              var ret = confirm('Start Dicom Search?');              var aetitle = document.getElementById("txtAETitle").value;              var patientid = document.getElementById("txtPatientId").value;              var accessnumber = document.getElementById("txtAccessionNumber").value;              var local = document.getElementById("cbLocal").checked;              if (ret == true) {                  window.location = 'myapp://,query,' + aetitle + ',' + patientid + ',' + accessnumber + ',' + local;              }              return;          };          function study() {              var ret = confirm('Open Study?');              var aetitle = document.getElementById("txtAETitle").value;              var studyInstanceUId = document.getElementById("txtStudyInstanceUId").value;              if (ret == true) {                  window.location = 'myapp://,study,' + aetitle + ',' + studyInstanceUId;              }              return;          };          function LaunchApp() {              try {                  var ret = confirm('Start myapp?');                  if (ret == true) {                      window.location = 'myapp://,start';                  }              }              catch (ex) {                  errMsg = "启动 myapp 报错.\n\n";                  alert(errMsg);              }              return;          };      </script>         <style type="text/css">           #txtAccessionNumber           {               width: 191px;           }           #txtStudyInstanceUId           {               width: 901px;           }       </style>  </head>  <body>      <div>         <input type="button" value="Open IView" onclick = "LaunchApp()" /><br /><br />          <label>AE Title: <input id="txtAETitle" type="text" value="AETITLE" /></label>          <label>PatientID: <input id="txtPatientId" type="text" value="115042300003"/></label>          <label>AccessionNumber: <input id="txtAccessionNumber" type="text" /></label>          <label>Search Local:<input id="cbLocal" type="checkbox" value="local" /></label><br />          <label>StudyInstanceUId: <input id="txtStudyInstanceUId" type="text" value="1.2.392.200036.9125.2.138612190166.20150423000027"/></label><br /><br />          <input type="button" value="Dicom Search" onclick = "dicom()" /><br /><br />          <input type="button" value="Open study" onclick = "study()" />      </div>  </body>  </html>  

8.来源

http://blog.csdn.net/jingliangliu/article/details/52648256

阅读全文
0 0
原创粉丝点击