Javascript 如何配置 IE 使“wscript.shell”工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2138002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to config IE to make "wscript.shell" work
提问by ablmf
I have some code that used to work. But I today when I try it again. I kept got "[object error]".
我有一些曾经可以工作的代码。但我今天再次尝试时。我一直收到“[对象错误]”。
I thought it's the problem of IE safety configure. But I can find how to config IE to make it work.
我以为是IE安全配置的问题。但我可以找到如何配置 IE 使其工作。
function Run() {
try {
var objShell = new ActiveXObject("wscript.shell");
objShell.Run("calc");
} catch(e) {
alert(e);
}
}
回答by Darin Dimitrov
You must enable ActiveX:
您必须启用 ActiveX:
- Click on Tools
- Select Internet Options...
- Select Securitytab.
- Select Internet in Web content zone.
- Then, click on Custom Level...
- Go through all the ActiveX setting there, select Promptor Enable
- 点击工具
- 选择Internet 选项...
- 选择安全选项卡。
- 在 Web 内容区域中选择 Internet。
- 然后,单击自定义级别...
- 在那里完成所有 ActiveX 设置,选择提示或启用
回答by houssam
it is Case Sensitive !!
区分大小写!!
<html>
<head>
<script language="javascript" type="text/javascript">
function OpenFile(){
alert ('Work');
var x = new ActiveXObject("WScript.Shell");
x.run('calc.exe');
}
</script>
</head>
<body>
<input type="button" value="GG" href="#" onclick="javascript:OpenFile();">
</body>
</html>
回答by RK4299
It may be necessary to make a change to the IE settings:
可能需要更改 IE 设置:
For example, for the Local intranet zone, you typically need to change a custom setting to "Initialize and script ActiveX controls not marked as safe for scripting."
例如,对于本地 Intranet 区域,您通常需要将自定义设置更改为“初始化和脚本未标记为安全脚本的 ActiveX 控件”。
I couldn't get the sample above to run without making the change.
我无法在不进行更改的情况下运行上面的示例。

