前端JS实现启动本地.exe客户端程序
使用url protocol 的方式来实现,亲测可行
步骤1:
先要写入注册表,先注册URL PROTOCOL, 在windows 下就是注册表,保存内容为 reg文件(myprotocol.reg),然后执行,就加入注册表,注册了这个名字为myprotocol 的协议.
使用文本新建.txt 写入以下内容,然后修改后缀名为.reg ,双击执行
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\myprotocol]
@="myprotocol Protocol"
"URL Protocol"= ""
[HKEY_CLASSES_ROOT\myprotocol\DefaultIcon]
@="D:\\soft\\WeChat\\WeChat.exe" // 我这里假设启动的是微信,注意用
[HKEY_CLASSES_ROOT\myprotocol\shell]
@= ""
[HKEY_CLASSES_ROOT\myprotocol\shell\open]
@= ""
[HKEY_CLASSES_ROOT\myprotocol\shell\open\command]
@="\"D:\\soft\\WeChat\\WeChat.exe\"" // 我这里假设启动的是微信
步骤2:
测试页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="public/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>前端JS实现启动本地.exe客户端程序</title>
</head>
<body>
<a href="myprotocol://">
打开程序
</a>
</body>
</html>