自定义浏览器协议,实现web程序调用本地程序

参考了一下qq的方式。

tencent://Message/?Uin=000000&websiteName=qzone.qq.com&Menu=yes

 

在注册表里面添加下面,就能实现

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Tencent]
"URL Protocol"="C:\\Program Files\\Tencent\\QQ\\Bin\\Timwp.exe"
@="TencentProtocol"

[HKEY_CLASSES_ROOT\Tencent\DefaultIcon]
@="C:\\Program Files\\Tencent\\QQ\\Bin\\Timwp.exe,1"

[HKEY_CLASSES_ROOT\Tencent\shell]

[HKEY_CLASSES_ROOT\Tencent\shell\open]

[HKEY_CLASSES_ROOT\Tencent\shell\open\command]
@="\"C:\\Program Files\\Tencent\\QQ\\Bin\\Timwp.exe\" \"%1\""

 

于是自己模仿着制作了一个,点击链接,弹出计算器。

首先是链接,超级简单 <a href="bbfexe://123456">计算器</a>

接下来就是建立注册表文件。复制下面代码到记事本,另存为.reg文件即可。

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\bbfexe]
"URL Protocol"="C:\\WINDOWS\\system32\\calc.exe"
@="TencentProtocol"

[HKEY_CLASSES_ROOT\bbfexe\DefaultIcon]
@="C:\\WINDOWS\\system32\\calc.exe,1"

[HKEY_CLASSES_ROOT\bbfexe\shell]

[HKEY_CLASSES_ROOT\bbfexe\shell\open]

[HKEY_CLASSES_ROOT\bbfexe\shell\open\command]
@="\"C:\\WINDOWS\\system32\\calc.exe\" \"%1\""

 

%1就是参数,在我的例子里面就是 123456

winform 中 static void Main(string[] args) 
args就是传过来的参数 %1