Javascript ActiveXObject 创建错误“自动化服务器无法创建对象”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4153841/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:08:11  来源:igfitidea点击:

ActiveXObject creation error " Automation server can't create object"

javascriptinternet-exploreractivex

提问by Asanka

I have a very simple javascript code,

我有一个非常简单的javascript代码,

<script language="javascript">          
         function RunExe()   
         {  
           w = new ActiveXObject("WScript.Shell");
           w.run('notepad.exe');
           return true;

         }  
</script>
    <form id="form1">
    <div>
      <input type="button" value="Run" onclick="return RunExe()" />
    </div>
    </form>

Which create an activeX object to run notepad.exe, if I save this in a plain html and run it in the IE, it works fine opening up the notepad, but if I insert this into a aspx page and run it, it will give an error called "Automation server can't create object", I googled it many times, but the IE security things I have already done and I think it's something in ASP or IIS which I couldn't figure out.

创建一个activeX对象来运行notepad.exe,如果我将它保存在一个普通的html中并在IE中运行它,它可以很好地打开记事本,但是如果我将它插入一个aspx页面并运行它,它会给一个名为“自动化服务器无法创建对象”的错误,我用谷歌搜索了很多次,但我已经完成了 IE 安全方面的事情,我认为这是我无法弄清楚的 ASP 或 IIS 中的问题。

Your suggestions and inputs are highly appreciable.

您的建议和意见非常值得赞赏。

Thanx

谢谢

采纳答案by epascarello

Well you can not run code from notepad so that means you are opening up the page from the file system. aka c:/foo/bar/hello.html

好吧,您无法从记事本运行代码,这意味着您正在从文件系统打开页面。又名 c:/foo/bar/hello.html

When you run the code from the asp.net page, you are running it from localhost. aka http://loalhost:1234/assdf.html

当您从 asp.net 页面运行代码时,您正在从 localhost 运行它。又名http://loalhost:1234/assdf.html

Each of these run in different security zones on IE.

每个都在 IE 上的不同安全区域中运行。

回答by Chandra Malla

This is caused by Security settings for internet explorer. You can fix this,by changing internet explorer settings.Go To Settings->Internet Options->Security Tabs. You will see different zones:i)Internet ii)Local Intranet iii)Trusted Sites iv)Restricted Sites. Depending on your requirement select one zone. I am running my application in localhost so i selected Local intranet and then click Custom Level button. It opens security settings window. Please enable Initialize and script Activex controls not marked as safe for scripting option.It should work.

这是由 Internet Explorer 的安全设置引起的。您可以通过更改 Internet Explorer 设置来解决此问题。转到“设置”->“Internet 选项”->“安全选项卡”。您将看到不同的区域:i) 互联网 ii) 本地内联网 iii) 受信任的站点 iv) 受限站点。根据您的要求选择一个区域。我在 localhost 中运行我的应用程序,所以我选择了本地内联网,然后单击自定义级别按钮。它打开安全设置窗口。请启用未标记为安全的脚本选项的初始化和脚本 Activex 控件。它应该可以工作。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by scunliffe

For this to work you have to really, really loosen your security settings (generally NOT recommended)

为此,您必须非常非常放松​​您的安全设置(通常不推荐)

You will need to add the website to your "Trusted Zone", then go into the custom settings (scroll about 1/2 way down the page) and change:

您需要将网站添加到您的“受信任区域”,然后进入自定义设置(向下滚动页面约 1/2)并更改:

ActiveX controls and plugins - Enable (or prompt)... any of the settings that apply to your code (I think the very last one is the one you are hitting) -- "script ActiveX controls marked safe for scripting*"

ActiveX 控件和插件 - 启用(或提示)...适用于您的代码的任何设置(我认为最后一个是您正在点击的设置)--“脚本 ActiveX 控件标记为安全脚本*”

That all said, unless you have a really, really good reason for doing this - you are opening up a major "hole" in your browsers security... step very carefully... and do notexpect that other end users will be willing to do the same.

话虽如此,除非你有一个非常非常好的理由这样做 - 你在你的浏览器安全中打开了一个主要的“漏洞”......非常小心......不要指望其他最终用户会愿意做同样的事情。

回答by Dafy Sequera

i also have same problem and solve it. Please go through the link

我也有同样的问题并解决了。请通过链接

add your site to trusted zone and change following options in ie Tools Menu -> Internet Options -> Security -> Custom level -> "Initialize and script ActiveX controls not marked as safe for scripting"

将您的站点添加到受信任区域并在 ie 工具菜单 -> Internet 选项 -> 安全 -> 自定义级别 ->“初始化和脚本未标记为脚本安全的 ActiveX 控件”中更改以下选项

http://forums.codeguru.com/showthread.php?t=256114

http://forums.codeguru.com/showthread.php?t=256114

回答by Mandoleen

I have the same problem , it solved by registering the dll

我有同样的问题,通过注册dll解决了

at project properties => build => register for COM interop => check it

在项目属性 => 构建 => 注册 COM 互操作 => 检查它

回答by Anele

This error is cause by security clutches between the web application and your java. To resolve it, look into your java setting under control panel. Move the security level to a medium.

此错误是由 Web 应用程序和您的 java.util.Date 之间的安全离合器引起的。要解决它,请查看控制面板下的 java 设置。将安全级别移至中等。