- 注:
- 1、ie设置--降低安全级别如 Intenet选项——安全——自定义级别——对未标记的ActiveX控...————启用
- 2、路径中含空格
- a:用%20代替空格
-
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>js</title>
- <script language="JavaScript">
- function open_exe(shellp)
- {
- try
- {
- a=new ActiveXObject("wscript.shell");
- a.run(shellp);
- }
- catch(e)
- {
- alert('找不到文件"'+shellp+'"(或它的组件之一)。请确定路径和文件名是否正确.')
- }
- }
- </script>
- </head>
- <body>
- <button onclick="open_exe('file:///F:/2/1.exe')">打开1</button>
- <button onclick="open_exe('file:///C:/Program%20Files%20(x86)/QQ2013/Bin/QQ.exe')">打开QQ</button>
- </body>
- </html>
- b:如下解决思路(转自网络)
- <html>
- <head>
- <title>RTX</title>
- <script>
- function exec () {
- var command;
- var shell = new ActiveXObject("WScript.Shell");
- command = shell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Tencent\\RTXC\\INSTDIR");//从注册表获得软件安装路径
- command = command + "RTX.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>
- </head>
- <body>
- <center><a href="javascript:" οnclick="exec()">RTX测试</a></center>
- </body>