场景:用js执行本地的安装软件,若是不存在就执行安装javascript
操做步骤:html
1.前台js代码 java
<script type="text/javascript"> function exec () { var command; var shell = new ActiveXObject("WScript.Shell"); try { command = shell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\Directory\\shell\\RadiAnt\\Icon");//从注册表得到软件安装路径 } catch(e) { if(window.confirm("你可能尚未安装Radiant,请下载安装")){ //alert("肯定"); window.location.href="jspView/radiantsetup32312921.exe"; return false; }else{ return false; } }//执行exe程序 window.oldOnError = window.onerror; window._command = command; window.onerror = function (err) { if (err.indexOf('utomation') != -1) { alert('命令' + window._command + ' 已经被用户禁止!'); return true; } else return false; }; var wsh = new ActiveXObject('WScript.Shell'); if (wsh) wsh.Run("\""+command); //解决目录包含空格问题 window.onerror = window.oldOnError; } </script>
执行exec()就能调用本地软件了shell
如下是须要注意的几点浏览器
1.该程序只能在IE上执行安全
2.注册表路径的查找步骤服务器
右键-复制项名称jsp
3.想要执行改程序必须更改本地的浏览器安全级别spa
不然报错:ERROR:Automation 服务器不能建立对象3d
具体参考百度文档:http://jingyan.baidu.com/article/ae97a646d43dc8bbfd461d0b.html