Recently there was a requirement to invoke the local exe program through JS. Use a registry and record the operation process deliberately.
Step 1: Write the registry
Create a new TXT document and write the following: Note that you need to replace the “Forensic” and exe addresses with your own.
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\" "
Copy the code
Change the text document.txt to.Reg file, double-click to run. After success, you can open the registry and see the new registry key
Step 2: Create an HTML file
The runtime here passes an argument to the 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, "> <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>Copy the code
Done!