Registering the Application Handling the Custom URI Scheme

To register an application to handle a particular URI scheme, add a new key, along with the appropriate subkeys and values, to HKEY_CLASSES_ROOT. The root key must match the URI scheme that is being added. For instance, to add an "alert:" scheme, add an alert key to HKEY_CLASSES_ROOT, as follows:

HKEY_CLASSES_ROOT
   alert
      URL Protocol = ""

Under this new key, the URL Protocol string value indicates that this key declares a custom pluggable protocol handler. Without this key, the handler application will not launch. The value should be an empty string.

Keys should also be added for DefaultIcon and shell. The Default string value of the DefaultIcon key must be the file name to use as an icon for this new URI scheme. The string takes the form "path, iconindex" with a maximum length of MAX_PATH. The name of the first key under the shell key should be an action verb, such as open. Under this key, a command key or a DDEEXEC key indicate how the handler should be invoked. The values under the command and DDEEXEC keys describe how to launch the application handling the new protocol.

Finally, the Default string value should contain the display name of the new URI scheme. The following example shows how to register an application, alert.exe in this case, to handle the alert scheme.

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

When a user clicks a link containing your custom URI scheme, Windows Internet Explorer launches the pluggable protocol handler registered for that URI scheme. If the specified open command specified in the registry contains a %1 parameter, Internet Explorer passes the URI to the registered pluggable protocol handler application.


  • 在注册表里新建register key

在注册表里新建一个key,按照URL protocol的格式,设置好路径。

也可以写一个.reg文件,打开文件即可注册key了。

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\HelloRio]
"URL Protocol"="C:\\Program Files (x86)\\HelloRio\\HelloRio.exe"
@="HelloRioProtocol"
[HKEY_CLASSES_ROOT\HelloRio\DefaultIcon]
@="C:\\Program Files (x86)\\HelloRio\\HelloRio.exe,1"
[HKEY_CLASSES_ROOT\HelloRio\shell]
[HKEY_CLASSES_ROOT\HelloRio\shell\open]
[HKEY_CLASSES_ROOT\HelloRio\shell\open\command]
@="\"C:\\Program Files (x86)\\HelloRio\\HelloRio.exe\" \"%1\""

第一行表示用的注册表工具

然后就是对应需要新建项在注册表中的路径,以及对应键值。双击该文件,即可自动在注册表中注册一个URL Protocol。

写一个test的html。或者在地址行直接键入。

最后就会提示luanch你的exe了。这里我写了一个比较简单的应用程序,实际上当我们在register key,%1代表我们接受参数。

实际上传入的参数是HelloRio:myrio,这里需要解析字符串。本来想用正则表达式,无奈正则表达式学得不好。+。+

#include <Windows.h>
#include <iostream>
#include <cstring>
#include <regex> using namespace std; int main(int argc,char* argv[]){
if(argc<){
MessageBox(NULL,TEXT("Please input a parameter£¡"),TEXT("HelloRio"), MB_OK);
exit();
}
else{ string s1=string(argv[]);
//search the right parameter auto i=find(s1.begin(),s1.end(),':');
i++;
string s2="hello"+string(i,s1.end());
wstring tmp(s2.begin(),s2.end());
const wchar_t* t=tmp.c_str();
t+='\0';
MessageBox(NULL,t,TEXT("HelloRio"), MB_OK);
return ;
}
}

腾讯的key:


用JavaScript在HTML里打开exe,需要Active X且不被浏览器接受(因为安全性因素)

<html>
<head>
<script language="javascript">
function Run(strPath)
{
var objShell = new ActiveXObject("wscript.shell");
objShell.exec(strPath);
objShell = null;
}
</script>
</head>
<body>
请输入要运行的程序路径:<br>
<input name=exe type=text size=20 value="D:\\a.doc">
<BUTTON class=button onclick="Run(exe.value)">确定</BUTTON>
</body>
</html>

利用URL protocol在网页打开本地exe的更多相关文章

  1. 利用URL Protocol实现网页调用本地应用程序

    http://blog.csdn.net/zssureqh/article/details/25828683

  2. Js调用exe程序方法(通过URL Protocol实现网页调用本地应用程序)

      1.使用记事本(或其他文本编辑器)创建一个protocal.reg文件,并写入以下内容 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROO ...

  3. 利用Pluggable Protocol实现浏览器打开本地应用程序

    https://www.cnblogs.com/liushaofeng89/archive/2016/05/03/5432770.html

  4. html网页调用本地exe程序的实现方法:

    html网页调用本地exe程序的实现方法:1.新建注册表具体文件: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\hhtpexe] [ ...

  5. PHP 网页调用本地exe程序实例

    一.需求:在做网站的时候,有些网站网页面需要调用本地的exe程序. 二.方法:利用注册URL Protocol的方式. 代码如下: 1.视图文件里面的代码: <a href="fyex ...

  6. 利用Register protocol实现网页调用桌面程序(类似迅雷、QQ等)

    前言 我们经常看到 tencent://.. thunder://     这两种开头的网址,往往觉得很奇怪,很想弄懂其中的原理,是如何实现的,我查找了相关的 资料,终于找到了,跟大家分享下. 原理篇 ...

  7. html网页调用本地exe程序

    1.使用记事本(或其他文本编辑器)创建一个protocal.reg文件,并写入以下内容 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\ ...

  8. html网页调用本地exe程序的实现方法(转)

    https://blog.csdn.net/ilovecr7/article/details/46803711 最近在做一个项目,要什么网页里调exe...开始以为不能实现,后来想想很多就跟淘宝网页上 ...

  9. JS IE 打开本地exe程序

    例: try{ //新建一个ActiveXObject对象 var exe = new ActiveXObject("wscript.shell"); var exePath = ...

随机推荐

  1. 轻量级代码生成器-OnlyCoder 第二篇

    最近利用业余时间将OnlyCoder又重新打造了一番,使其使用起来更简单.更顺手. 相关的帮助文档也已发布了版本. 界面改版,UI采用了DotNetBar2组件. 还是先看下UI效果吧. 由于使用了  ...

  2. python编程快速上手之第4章实践项目参考答案

    #!/usr/bin/env python3.5 # coding:utf-8 # 假定有一个列表,编写函数以一个列表值作为参数,返回一个字条串 # 该字符串包含所有表项,之间以逗号和空格分隔,并在最 ...

  3. Linux学习笔记(二)——文件/目录/VIM

    文件和目录管理 及 VI编辑器的使用 文件和目录管理,刚开始学这块的时候感觉内容很多很杂,但是学完进行总结后,发现其实很有条理的而且没什么难度,只是熟练掌握这些常用的命令就行了.至于Vim编辑器,不得 ...

  4. python新手之2变量

    变量 变量是将储存的值保存在内存中.当声明一个变量的时候会在内存中开辟一个储存内容的位置. 基于变量的数据类型,解释器分配内存空间并决定储存的内容.因此我们可以通过变量分配不同的数据类型,可以在变量中 ...

  5. requireJS 源码(三) data-main 的加载实现

    (一)入口 通过 data-main 去加载 JS 模块,是通过  req(cfg) 入口去进行处理的. 为了跟踪,你可以在此 加断点 进行调试跟踪. (二)  req({ })执行时,functio ...

  6. windows环境下,anoconnda安装tensorflow

    最近对深度学习研究比较多,目前最火的Python深度学习库应该是tensorflow了. 为了方便,本人在windows下用anaconda来使用python,且同时安装了,anaconda2,3,3 ...

  7. 快速搞定selenium grid分布式

    写这篇文章,似乎有点重复造轮子的嫌疑.当看了几篇相关文章后,我还是决定把半年前的半成品给完成了. 以传统的方式部署分布式Selenium Grid集群需要耗费大量时间和机器成本来准备测试环境. Sna ...

  8. iOS开发实战-上架AppStore 通过内购和广告获得收益

    写在前面 由于一些原因需要离职,准备重回大上海 忽然发现手头上也没什么独立App,那就随便写个放到AppStore上吧,凑个数吧.哈哈哈. 这个App是无聊找配色的时候看到的一套图 正好春节在家没什么 ...

  9. 【TOP】top命令的load average的意义

    一. 怎么查看机器负载 uptime 命令: $uptime 14:32:32 up 108 days, 23:04, 17 users,  load average: 0.06, 0.08, 0.0 ...

  10. 【CSS3】使用CSS3线性渐变实现图片闪光划过效果(转)

    原文:http://www.nowamagic.net/librarys/veda/detail/2600 资料参考: http://www.cnblogs.com/lhb25/archive/201 ...