web打开exe程序

web打开exe程序

一、思路

如果想要web调用本地应用程序,可以通过自定义URL Protocol来调用应用程序。

浏览器在解析到自定义URL Protocol之后,会寻找注册表,然后通过注册表启动相应的程序。这样就可以在WEB页面调到你的程序了。比如在浏览器地址栏输入“tencent://message/?uin=88888888&Site=JooIT.com&Menu=yes”就会出现一个QQ对话框。

二、实现

1、新建.reg文件,并运行

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT注册表名]
"URL Protocol"="程序路径"
@="注册表名Protocol"
[HKEY_CLASSES_ROOT注册表名DefaultIcon]
@="程序路径,1"
[HKEY_CLASSES_ROOT注册表名shell]
[HKEY_CLASSES_ROOT注册表名shellopen]
[HKEY_CLASSES_ROOT注册表名shellopencommand]
@=""程序路径" "%1""

其中,@=""程序路径"  "%1"",此处的%1表示传入的参数,比如:tencent://message,解析后就可以得到参数message。

保存为.reg文件并运行。

2、web页面调用

在网页上可以直接通过一个超链接调用。

超链接格式:

协议://参数

3、示例

new.reg文件

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTImou]
"URL Protocol"="D:\Software\imou\bin\imou.exe"
@="ImouProtocol"
[HKEY_CLASSES_ROOTImouDefaultIcon]
@="D:\Software\imou\bin\imou.exe,1"
[HKEY_CLASSES_ROOTImoushell]
[HKEY_CLASSES_ROOTImoushellopen]
[HKEY_CLASSES_ROOTImoushellopencommand]
@=""D:\Software\imou\bin\imou.exe" "%1""

index.html文件

<html>
<body>
<a href="imou://">运行</a>
</body>
</html>

点击运行就会出现

web打开exe程序