1、ie浏覽器
try {
let objShell=new ActiveXObject("WScript.Shell");
objShell.Run("D:\\model\\test.exe");
} catch (error) {
console.log(error)
}
2、相容其他浏覽器(推薦)
-
寫入系統資料庫
建立read.reg檔案,編寫如下代碼。
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\myprotocol]
@="myprotocol Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\myprotocol\DefaultIcon]
@="C:\Users\Administrator\Desktop\ie10.exe"
[HKEY_CLASSES_ROOT\myprotocol\shell]
@=""
[HKEY_CLASSES_ROOT\myprotocol\shell\open]
@=""
[HKEY_CLASSES_ROOT\myprotocol\shell\open\command]
@="\"C:\\Users\\Administrator\\Desktop\\ie10.exe\""
儲存,并執行reg檔案。
-
執行完成後,确認系統資料庫已注冊。
win+r,輸入regegit回車。
js執行本地exe程式 - 編寫html檔案。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>執行exe</title>
</head>
<body>
<a href="myprotocol://">
執行桌面上的ie10.exe程式
</a>
</body>
</html>
運作如圖。