如何知道 Internet Explorer 中是否启用了 ActiveX
2009-02-06 15:40
387 查看
如何知道 Internet Explorer 中是否启用了 ActiveX?
问:您好,脚本专家!如何知道 Internet Explorer 中是否启用了 ActiveX?
-- JV
答:
您好,JV。您一定要问这个问题,是吗?实际上,这并不是一个特别难回答的问题,只是有点复杂。不过,那与配置 Internet Explorer 的方式紧密相关,而与通过编写一个脚本来检索此信息关系不大。
首先,Internet Explorer 没有管理对象模型;相反,我们能够通过编程的方式检索 Internet Explorer
设置和属性值的唯一方法就是通过编写一个脚本来从注册表中获取此信息。这相当容易;我们经常在本专栏中使用注册表读取的脚本。最为棘手的部分就是搞清楚需
要读取哪个注册表值,并知道如何解释返回的数据。
注意:另一个棘手的部分在于知道您对哪个 ActiveX 设置感兴趣;不论好坏,Internet Explorer 有与 ActiveX 控件相关的多个设置。在今天的专栏中,我们假定您要读取此设置的值:运行 ActiveX 控件和插件。 |
区域名 | 区域值 |
Intranet 站点 | 1 |
受信任的站点 | 2 |
Internet 站点 | 3 |
受限制的站点 | 4 |
部分中找到 Internet Explorer
安全区域的设置;要访问某个特定区域,您需要访问与该区域对应的子项。要确定相应的子项,只需将区域值追加到前面的注册表路径即可。例如,要获取
Internet 站点区域(值 3)的设置,您需要访问以下注册表子项:
HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/Zones/3
您能看到 3 被追加到了末尾处。要访问 Intranet 站点区域(值 1)的设置?没问题:
HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings/Zones/1
找到正确的注册表子项后,您需要知道要读取哪个注册表值。遗憾的是(至少对于脚本编写者来说),这些注册表值的名称有点含糊;例如,我们感兴趣的名称为 1200。(为什么是这样呢?我们不知道。)如果您对使用脚本来读取/管理 Internet Explorer 设置感兴趣,那么,您可能希望阅读一下 Managing Internet Explorer Enhanced Security Configuration whitepaper(英文)。仅一部分文档会涉及脚本编写,但是,该部分的确将这些含糊的注册表值映射到了用户界面中的相应属性。当然,许多这样的设置都可在 Tweakomatic 中找到。(Tweakomatic 与白皮书不同,它会真正地为您编写脚本。)
那么,我们已准备最终编写一个脚本并真的在此执行一些操作吗?几乎是这样。您需要知道的另一件事就是配置信息作为双字节(数字)值被存储在注册表中。如果您知道 ActiveX 控件被配置为 3 而不是 65536,这会有所帮助吗?可能没有。不过,下表可能有所帮助:
注册表值 | 用户界面值 |
0 | Enabled |
1 | Prompt |
3 | Disabled |
65536 | Administrator Approved |
那好,现在我们就准备编写一个脚本。下面的这个示例脚本可检索 Intranet 站点区域(区域值 1)的设置信息:
HKEY_CURRENT_USER = &H80000001 strComputer = "." Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv") strKeyPath = "Software/Microsoft/Windows/CurrentVersion/Internet Settings/Zones/1" ValueName = "1200" objReg.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue Wscript.Echo "Run ActiveX Controls and Plug-ins" If IsNull(dwValue) Then Wscript.Echo "Intranet sites: The value is either Null or could not be found in the registry." ElseIf dwValue = 0 Then Wscript.Echo "Intranet sites: Enabled" ElseIf dwValue = 1 Then Wscript.Echo "Intranet sites: Prompt" ElseIf dwValue = 3 Then Wscript.Echo "Intranet sites: Disabled" ElseIf dwValue = 65536 Then Wscript.Echo "Intranet sites: Administrator Approved" End If
我们首先定义一个名为 HKEY_CURRENT_USER 的常量并将其值设置为 &H80000001;这将告诉脚本我们要使用哪个注册表配置单元。然后我们连接到 WMI 服务;请注意,StdRegProv(标准注册表提供程序)类位于 root/default 命名空间中。(许多脚本编写者都认为该类与大多数 WMI 类一样,都位于 root/cimv2 中。事实并非如此。)
接下来我们将为一对变量赋值:
strKeyPath = "Software/Microsoft/Windows/CurrentVersion/Internet Settings/Zones/1" ValueName = "1200"
正如您所看到的,变量 strKeyPath 包含 HKEY_CURRENT_USER 中的注册表路径(请勿在该路径中包含
HKEY_CURRENT_USER,否则,脚本将失败)。同时,将变量 ValueName 设置为 1200,该值恰好为我们要读取的注册表值。
然后我们调用 GetDWORDValue 方法,这样我们可读取注册表中的双字节值:
objReg.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue
请注意,我们需要向 GetDWORDValue 传递几个参数:
• | HKEY_CURRENT_USER,告诉脚本要使用哪个注册表配置单元的常量。 |
• | strKeyPath,包含注册表路径的变量。 |
• | ValueName,表示我们要读取的注册表值的变量。 |
• | dwValue,将结束存储从注册表中读取的值的“输出参数”。如果您正在想,“请稍等,我们没有为 dwValue 赋值,”您说对了。我们就是这样设计的:我们不为输出参数赋值。相反,GetDWORDValue 将读取恰好存储在所讨论的注册表值 (1200) 中的任何值,然后该方法会将该值赋给 dwValue。 |
此时,我们可只回显从注册表中检索的值。不过,正如我们所指出的那样,该检索值将为诸如 1、3 或 65536 这样的值。因此,我们建立一个简单小巧的 If Then ElseIf 块以检查返回值,并回显一个更有意义的消息:
If IsNull(dwValue) Then Wscript.Echo "Intranet sites: The value is either Null or could not be found in the registry." ElseIf dwValue = 0 Then Wscript.Echo "Intranet sites: Enabled" ElseIf dwValue = 1 Then Wscript.Echo "Intranet sites: Prompt" ElseIf dwValue = 3 Then Wscript.Echo "Intranet sites: Disabled" ElseIf dwValue = 65536 Then Wscript.Echo "Intranet sites: Administrator Approved" End If
您说对了:一旦您知道值存储在注册表中的什么位置以及如何将值存储在注册表中,这就相当容易了。
仅仅为了省去键入(和/或复制与粘贴)之苦,下面的脚本可返回所有四个安全区域的信息:
HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
strKeyPath = "Software/Microsoft/Windows/CurrentVersion/Internet Settings/Zones/1" ValueName = "1200"objReg.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValueWscript.Echo "Run ActiveX Controls and Plugins"
If IsNull(dwValue) Then Wscript.Echo "Intranet sites: The value is either Null or could not be found in the registry." ElseIf dwValue = 0 Then Wscript.Echo "Intranet sites: Enabled" ElseIf dwValue = 1 Then Wscript.Echo "Intranet sites: Prompt" ElseIf dwValue = 3 Then Wscript.Echo "Intranet sites: Disabled" ElseIf dwValue = 65536 Then Wscript.Echo "Intranet sites: Administrator Approved" End IfstrKeyPath = "Software/Microsoft/Windows/CurrentVersion/Internet Settings/Zones/2"
ValueName = "1200"
objReg.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValueIf IsNull(dwValue) Then
Wscript.Echo "Trusted sites: The value is either Null or could not be found in the registry."
ElseIf dwValue = 0 Then
Wscript.Echo "Trusted sites: Enabled"
ElseIf dwValue = 1 Then
Wscript.Echo "Trusted sites: Prompt"
ElseIf dwValue = 3 Then
Wscript.Echo "Trusted sites: Disabled"
ElseIf dwValue = 65536 Then
Wscript.Echo "Trusted sites: Administrator Approved"
End If
strKeyPath = "Software/Microsoft/Windows/CurrentVersion/Internet Settings/Zones/3"
ValueName = "1200"
objReg.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValueIf IsNull(dwValue) Then
Wscript.Echo "Internet sites: The value is either Null or could not be found in the registry."
ElseIf dwValue = 0 Then
Wscript.Echo "Internet sites: Enabled"
ElseIf dwValue = 1 Then
Wscript.Echo "Internet sites: Prompt"
ElseIf dwValue = 3 Then
Wscript.Echo "Internet sites: Disabled"
ElseIf dwValue = 65536 Then
Wscript.Echo "Internet sites: Administrator Approved"
End If
strKeyPath = "Software/Microsoft/Windows/CurrentVersion/Internet Settings/Zones/4"
ValueName = "1200"
objReg.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValueIf IsNull(dwValue) Then
Wscript.Echo "Restricted sites: The value is either Null or could not be found in the registry."
ElseIf dwValue = 0 Then
Wscript.Echo "Restricted sites: Enabled"
ElseIf dwValue = 1 Then
Wscript.Echo "Restricted sites: Prompt"
ElseIf dwValue = 3 Then
Wscript.Echo "Restricted sites: Disabled"
ElseIf dwValue = 65536 Then
Wscript.Echo "Restricted sites: Administrator Approved"
End If
运行脚本,将返回类似下面内容的输出:
Run ActiveX Controls and Plugins Intranet sites: Enabled Trusted sites: Enabled Internet sites: Enabled Restricted sites: Disabled
在此我们还能再做些什么吗?或许可以;毕竟我们还可配置此注册表值。但那是改天要讨论的内容了。
相关文章推荐
- 如何判别Tomcat是否已经启用了APR
- 用vbs检测Internet Explorer 中是否启用了 ActiveX
- 如何知道一个开发人员是否能融入团队?
- 怎么知道网站是否被黑以及如何应对防御被黑
- 大数据架构和模式(二)如何知道一个大数据解决方案是否适合您的组织
- 如何知道自己的计算机是否安装了.Net Framework 1.1
- 如何知道自己的电脑是否共享
- 教你如何知道MSN的好友是否阻止了你
- android 广告平台—杀毒软件是如何知道是否有广告的
- js如何知道checkbox是否被选中,并且选中的话让input元素变为不可编辑
- 如何查看spider蜘蛛,那么怎么才能知道蜘蛛是否来过你的站?
- 如何判断是否启用了OpenGL硬件加速
- 如何知道使用的sql server 2000是否打了补丁sp4?
- 如何知道是否Oracle安装成功
- [原创]SQL Server2005中如何知道某个存储过程是否已加密?
- 如何知道自动任务模块是否运行?
- Solaris10如何确认DirectIO是否已经启用
- 大数据架构和模式(二)如何知道一个大数据解决方案是否适合您的组织
- 如何知道ADODB.COMMAND的execute是否成功
- 大数据架构和模式(一)大数据分类和架构简介 大数据架构和模式(二)如何知道一个大数据解决方案是否适合您的组织