Use VBS to detect if Activex_vbs is enabled in Internet Explorer

Source: Internet
Author: User
Tags object model

Ask:

Hello, Scripting Guy! How do I know if ActiveX is enabled in Internet Explorer?

--JV

For:

Hello, JV. You must ask the question, won't you? In fact, this is not a particularly difficult question to answer, but a little complicated. However, that is closely related to how Internet Explorer is configured, and is not relevant to retrieving this information by writing a script.

First, Internet Explorer does not have a managed object model; Instead, the only way we can programmatically retrieve Internet Explorer settings and property values is by writing a script to get this information from the registry. This is fairly easy; We often use registry-readable scripts in this column. The hardest part is figuring out which registry value to read and how to interpret the returned data.

Note : Another tricky part is knowing which ActiveX settings you're interested in, and for good or bad, Internet Explorer has multiple settings associated with ActiveX controls. In today's column, we assume that you want to read the value of this setting: Run ActiveX controls and Plug-ins .

Let's start by figuring out which registry values need to be modified. In fact, Internet Explorer security settings do not have global settings; Instead, these settings are managed by the Internet Explorer zone. There are four such security zones; The zone name and its value are shown in the following table:

Area Domain Name

Zone value

Intranet Sites

1

Trusted Sites

2

Internet Sites

3

Restricted Sites

4

Can be found in the hkey_current_user\ software\microsoft\windows\currentversion\internet settings\zones\ section of the Registry Internet Explorer security zone settings; To access a specific area, you need to access the subkey that corresponds to that zone. To determine the corresponding subkey, simply append the zone value to the previous registry path. For example, to get the settings for the Internet site zone (value 3), you need access to the following registry subkey:

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

You can see that 3 is appended to the end. Do you want to access the settings for the Intranet site area (value 1)? No problem:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet settings\zones\1

After you find the correct registry subkey, you need to know which registry value to read. Unfortunately (at least for scripting writers), the names of these registry values are somewhat ambiguous; for example, the name we are interested in is 1200. (Why is that so?) We don't know. If you are interested in using scripts to read/Manage Internet Explorer settings, you may want to read the managing Internet Explorer Enhanced Security Configuration Whitepaper(English). Only a portion of the document involves scripting, but it does map these ambiguous registry values to the corresponding properties in the user interface. Of course, many of these settings can be found in Tweakomatic . (unlike the white paper, Tweakomatic will actually write scripts for you.) )

So, are we ready to end up writing a script and really doing something about it here? It's almost like that. The other thing you need to know is that the configuration information is stored in the registry as a Double-byte (numeric) value. Would it help if you knew that ActiveX controls were configured to be 3 instead of 65536? Probably not. However, the following table may help:

Registry value

User interface face value

0

Enabled

1

Prompt

3

Disabled

65536

Administrator Approved

No, the last value is not a typographical error, it is indeed 65536. Go ahead and think for yourself.

Well, now we're going to write a script. The following example script retrieves settings information for the Intranet site area (Zone value 1):

hkey_current_user = &h80000001 StrComputer = "." Set Objreg = GetObject ("winmgmts:\\" & StrComputer & "\root\default:StdRegProv") strKeyPath = "Software\microsof T\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 to found in the registry. " ElseIf dwvalue = 0 Then WScript.Echo "Intranet sites:enabled" ElseIf dwvalue = 1 Then WScript.Echo "Intranet Sites:p Rompt "ElseIf dwvalue = 3 Then wscript.echo" Intranet sites:disabled "ElseIf dwvalue = 65536 Then WScript.Echo" Intra NET 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 hive we want to use. Then we connect to the WMI service; note that theStdRegProv(Standard Registry Provider) class is in the root\default namespace. (Many scripting people believe that this class, like most WMI classes, is located in root\cimv2.) That is not the case. )

Next we'll assign a value 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 the path, otherwise the script will fail). Also, set the variable valuename to 1200, which is exactly the registry value that we want to read.

Then we call the GetDWORDValue method so that 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_USERA constant that tells the script which registry hive to use.

strKeyPaththat contains the variables for the registry path.

ValueNamethat represents the variable of the registry value that we want to read.

dwvalue, "Output parameters" that store values that are read from the registry are ended. If you're thinking, "Wait a minute, we didn't assign a value to Dwvalue," you're right. That's how we designed it: we don't assign values to output parameters. Instead, GetDWORDValue reads any value that is stored exactly in the registry value (1200) being discussed, and then assigns the value to dwvalue.

This is really good, isn't it?

At this point, we can echo only the values retrieved from the registry. However, as we have pointed out, the retrieved value will be a value such as 1, 3, or 65536. So, we create a simple, compact If Then ElseIf block to check the return value and echo a more meaningful message:

If IsNull (dwvalue) Then
  wscript.echo "Intranet sites:the value is either Null or could no is found in the registry."
ElseIf dwvalue = 0 Then
  WScript.Echo "Intranet sites:enabled"
ElseIf dwvalue = 1 Then wscript.echo
  "Intranet Sites:prompt"
ElseIf D Wvalue = 3 Then
  WScript.Echo "Intranet sites:disabled"
ElseIf dwvalue = 65536 Then wscript.echo
  "Intranet sit Es:administrator Approved "End
If

You're right: once you know where the value is stored in the registry and how to store the value in the registry, this is pretty easy.

Just to save you the pain of typing (and/or copying and pasting), the following script returns information for all four security zones:

HKEY_CURRENT_USER = &h80000001 StrComputer = "." Set Objreg = GetObject ("winmgmts:\\" & StrComputer & "\root\default:StdRegProv") strKeyPath = "Software\microsof T\windows\currentversion\internet settings\zones\1 "valuename =" 1200 "Objreg.getdwordvalue HKEY_CURRENT_USER, strKeyPath, ValueName, Dwvalue WScript.Echo "Run ActiveX Controls and Plugins" If IsNull (dwvalue) Then WScript.Echo "I
Ntranet sites:the value is either Null or could not being found in the registry. " ElseIf dwvalue = 0 Then WScript.Echo "Intranet sites:enabled" ElseIf dwvalue = 1 Then WScript.Echo "Intranet Sites:p Rompt "ElseIf dwvalue = 3 Then wscript.echo" Intranet sites:disabled "ElseIf dwvalue = 65536 Then WScript.Echo" Intra NET Sites:administrator Approved "End If strKeyPath =" Software\Microsoft\Windows\CurrentVersion\Internet Settings\ Zones\2 "valuename =" 1200 "Objreg.getdwordvalue HKEY_CURRENT_USER, strKeyPath, ValueName, DwValue If IsNull (dwValue) Th En wscript.echo "Trusted siTes:the value is either Null or could isn't found in the registry. " ElseIf dwvalue = 0 Then wscript.echo "Trusted sites:enabled" ElseIf dwvalue = 1 Then wscript.echo "Trusted Sites:pro MPT "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, dwvalue If IsNull (dwValue) Then W Script.
Echo "Internet sites:the value is either Null or could isn't found in the registry." ElseIf dwvalue = 0 Then wscript.echo "Internet sites:enabled" ElseIf dwvalue = 1 Then wscript.echo "Internet Sites:p Rompt "ElseIf dwvalue = 3 Then wscript.echo" Internet sites:disabled "ElseIf dwvalue = 65536 Then WScript.Echo" Inter NET Sites:administrator Approved "End If strKeyPath =" Software\Microsoft\Windows\CurrentVersion\Internet Settings\zones\4 "valuename =" 1200 "Objreg.getdwordvalue HKEY_CURRENT_USER, strKeyPath, ValueName, DwValue If IsNull (d
Wvalue) Then wscript.echo "Restricted sites:the value is either Null or could no is found in the registry." ElseIf dwvalue = 0 Then wscript.echo "Restricted sites:enabled" ElseIf dwvalue = 1 Then wscript.echo "Restricted site S: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, which returns output similar to the following:

Run ActiveX Controls and Plugins
Intranet sites:enabled
Trusted sites:enabled
Internet sites:enabled
Restricted sites:disabled

What else can we do here? Maybe, after all, we can also configure this registry value. But that's what we're going to talk about sometime.

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.