Use vbs to check whether ActiveX is enabled in Internet Explorer

Source: Internet
Author: User

Q:

Hello, script expert! How do I know if ActiveX is enabled in Internet Explorer?

-- JV

A:

Hello, JV. YouYesAsk this question, right? In fact, this is not a very difficult question to answer, but it is a bit complicated. However, it is closely related to configuring Internet Explorer, but it is not related to retrieving this information by writing a script.

First, Internet Explorer does not manage object models. On the contrary, the only way to retrieve Internet Explorer settings and attribute values through programming is to get this information from the Registry by writing a script. This is quite easy; we often use scripts for registry reading in this column. The most tricky part is to figure out which registry value to read and how to explain the returned data.

Note:: The other tricky part is to know which ActiveX settings you are interested in. Internet Explorer has multiple settings related to ActiveX controls, good or bad. In today's column, we assume that you want to read the set value:Run ActiveX controls and plug-ins.

Let's start by figuring out which registry values need to be modified. In fact, no global settings are available for Internet Explorer security settings. On the contrary, these settings are managed by the Internet Explorer area. There are four such security zones. The region names and their values are shown in the following table:

Region name

Region value

Intranet site

1

Trusted Sites

2

Internet site

3

Restricted Sites

4

Available in the RegistryHKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet Settings \ Zones \To access a specific region, you need to access the Sub-item corresponding to the region. To determine the corresponding subitem, you only need to append the region value to the previous registry path. For example, to obtain the setting of the Internet site area (Value 3), you need to access the following registry subkeys:

HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet Settings \ Zones \3

You can see3Appended to the end. What are the settings for accessing the Intranet site region (value 1? No problem:

HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet Settings \ Zones \1

After finding the correct registry subitem, you need to know which registry value to read. Unfortunately (at least for script writers), the names of these registry values are a bit vague; for example, the names we are interested in are1200. (Why? We don't know .) If you are interested in using scripts to read/manage Internet Explorer settings, you may want to readManaging Internet Explorer Enhanced Security Configuration whitepaper(English ). Only one part of the document involves script writing. However, this partIndeedMap these vague registry values to corresponding properties on the user interface. Of course, many such settings can be found inTweakomatic. (Unlike the White Paper, Tweakomatic will actually write scripts for you .)

Then, we have prepared to write a script andRunSome operations? This is almost the case. Another thing you need to know is that the configuration information is stored in the registry as a double byte (number) value. If you know that the ActiveX control is configured as 3 rather than 65536, will this be helpful? May not. However, the following table may be helpful:

Registry Value

User Interface Value

0

Enabled

1

Prompt

3

Disabled

65536

Administrator Approved

No, the last value is not printed incorrectly. It does.Is65536. Think about it yourself.

Well,NowWe will prepare a script. The following sample script retrieves the settings of the Intranet site region (region value 1:

HKEY_CURRENT_USER = &H80000001strComputer = "."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 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

We first define a constant named HKEY_CURRENT_USER and set its value to & H80000001; this will tell the script which registry Configuration unit to use. Then we connect to the WMI Service. Please note that,StdRegProv(Standard registry provider) Class locatedRoot \ defaultNamespace. (Many script writers think that this class, like most WMI classes, is located in root \ cimv2. This is not the case .)

Next we will assign values to a pair of variables:

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1"ValueName = "1200"

As you can see, the variable strKeyPath contains the Registry path in HKEY_CURRENT_USER (do not include HKEY_CURRENT_USER in this path; otherwise, the script will fail ). At the same time, set the value of the variable ValueName to 1200, which is exactly the registry value we want to read.

Then we callGetDWORDValueIn this way, we can read the double byte values in the registry:

objReg.GetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue

Please note that we need to pass several parameters to GetDWORDValue:

HKEY_CURRENT_USERTo tell the script which registry Configuration unit constant to use.

StrKeyPathContains the Registry PATH variables.

ValueNameIndicates the variable of the registry value to be read.

DwValueTo end the "Output Parameters" of the values read from the registry ". If you are thinking, "Please wait, we didn't assign a value to dwValue," You are right. We designed it like this: WeNoAssign values to output parameters. Instead, GetDWORDValue reads any value that is exactly stored in the discussed registry value (1200), and thenMethodThe value is assigned to dwValue.

ThisIndeedPretty good, isn't it?

At this point, we can only display the value retrieved from the registry. However, as we have pointed out, the search value will be a value such as 1, 3, or 65536. Therefore, we create a simple and smallIf Then ElseIfBlock to check the return value and display a more meaningful message:

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

You are right: Once you know where the value is stored in the registry and how to store the value in the registry, this is quite easy.

To save the hassle of typing (and/or copying and pasting), the following script returns information for all four security zones:

HKEY_CURRENT_USER = &H80000001strComputer = "."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 IfstrKeyPath = "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 IfstrKeyPath = "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 the script and the output is similar to the following:

Run ActiveX Controls and PluginsIntranet sites: EnabledTrusted sites: EnabledInternet sites: EnabledRestricted sites: Disabled

What else can we do here? Maybe. After all, we can configure this registry value. But that is the content to be discussed in the next day.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.