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

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浏览器,若不能启动指定的应用,请查看如下几点

6.1 自定义协议后的参数不能太短,最好超过三个字符,并且最好不要用一些常用的关键字.

6.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>



  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值