/****************************** * 说明:运行Window应用程序 * * 备注:该方法只能在IE中运行,且存在较大的安全隐患,斟酌使用 * * 调用示例: var oApp = new Application(); oApp.Run("C:\\Windows\\notepad.exe"); **********************************/ function Application() { //参数:sPath 要执行应用程序路径 this.Run = function (sPath) { if (navigator.userAgent.indexOf("MSIE") <= 0) { alert("当前运行函数只支持IE!"); return; } if (FileCheck(sPath, "应用程序[" + sPath + "]不存在,请检查!!")) { var oWsShell = new ActiveXObject("WScript.Shell"); if (oWsShell) oWsShell.Run(sPath); oWsShell = null; } } function FileCheck(sPath, sNothingMessage) { try { var oFSO = new ActiveXObject("Scripting.FileSystemObject"); if (!oFSO.FileExists(sPath)) { oFSO = null; if (sNothingMessage) alert(sNothingMessage); return false; } return true; } catch (e) { var sErrorMessage = "命令已经被禁止!!请在IE选项的[安全]将此网站加入可信站点\n" + "并启动该自定义级别中的'对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本'选项,之后刷新页面" alert(sErrorMessage); return false; } } }