最近有个需求,需要通过js唤起本地的exe程序。使用注册表方式,操作过程特意记录一下。
第一步:编写注册表
新建一个txt文本文档,写入如下内容:注意将“Forensic”和exe地址替换成自己的。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Forensic]
@="Forensic Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\Forensic\DefaultIcon]
@="C:\Users\Downloads\Qt\forensicIDE-exec\bin\ForensicIDE.exe"
[HKEY_CLASSES_ROOT\Forensic\shell]
@=""
[HKEY_CLASSES_ROOT\Forensic\shell\open]
@=""
[HKEY_CLASSES_ROOT\Forensic\shell\open\command]
@="\"C:\Users\Downloads\Qt\forensicIDE-exec\bin\ForensicIDE.exe\" "
将文本文档.txt修改为.reg文件,双击运行。成功之后
能够打开注册表看到新建的注册表项
第二步:新建HTML文件
这边运行时向exe传递了一个参数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<a id="exeUrl" style="display: none;"></a>
</div>
</body>
<script type="text/javascript">
window.onload = function () {
getQuery('token');
}
function getQuery(name) {
var token;
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
token = unescape(r[2]);
Run(token)
}
}
function Run(token) {
const ga = document.getElementById('exeUrl')
ga.href = "Forensic://" + token
ga.click()
}
</script>
</html>
搞定!