Export (0) Print
Expand All

Zones-wmi.vbs

By The Scripting Guys, Microsoft Corporation

This script configures the settings for a specific Internet Explorer security zone by editing the registry, using the WMI System Registry provider. It can run against a local or remote computer.

The relevant security zone is indicated by the numerical value of the subkey under Zones in the path:

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

where the meaning of x is:

0 = Local Computer
1 = Intranet
2 = Trusted Sites
3 = Internet
4 = Restricted Sites

You can change this value in the variable strKeyPath to configure a different zone.

Zones-wmi.vbs corresponds to Zones.vbs, one of the scripts that ships with Application Compatibility Testing and Mitigation Guide for Windows XP Service Pack 2 and which are documented in the Appendix. You can download a Windows Installer (.msi) file that installs the Guide and its associated scripts from:

http://www.microsoft.com/downloads/details.aspx?FamilyId=9300BECF-2DEE-4772-ADD9-AD0EAF89C4A7&displaylang=en

To use the script, copy the code, paste it into Notepad, and then save the script as Zones-wmi.vbs. To run the script, open a command prompt window to the directory of the script and type:

cscript zones-wmi.vbs

If the default script host on the computer is Cscript.exe, the initial "cscript" may be omitted.

Script Code



'******************************************************************************
'Zones-wmi.vbs
'Author: Peter Costantini, the Microsoft Scripting Guys
'Date: 9/7/04
'Revision 1.0
'System requirement: Windows XP Service Pack 2.
'This script configures the settings for a specific Internet Explorer security
'zone. It can be run against a local or remote computer.
'The relevant security zone is indicated by the numerical value of the subkey
'under Zones in the path:
'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\
'Internet Settings\Zones\x where the meaning of x is:
'0 = Local Computer
'1 = Intranet
'2 = Trusted Sites
'3 = Internet
'4 = Restricted Sites
'You can change this value in strKeyPath to configure a different zone.

'******************************************************************************

On Error Resume Next

'Global variables
strComputer = "." ' Can be changed to name of remote computer.

'Connect with WMI service and StdRegProv class.
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
 strComputer & "\root\default:StdRegProv")
If Err = 0 Then
  SetValues
Else
  WScript.Echo "Unable to connect to WMI StdRegProv on " & strComputer & "."
  WScript.Echo "  Error Number:" & Err.Number
  WScript.Echo "  Source:" & Err.Source
  WScript.Echo "  Description:" & Err.Description
End If
Err.Clear

'******************************************************************************

Sub SetValues

'Local constants and variables
Const HKEY_CURRENT_USER = &H80000001
'Edit the final number in this registry path to change the zone.
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet " & _
 "Settings\Zones\1"
strEntryNameA1 = "DisplayName"
strValueA1 = "Local intranet"
strEntryNameA2 = "Description"
strValueA2 = "This zone contains all Web sites on local intranet."
strEntryNameA3 = "Icon"
strValueA3 = "shell32.dll#0018"
strEntryNameB1 = "CurrentLevel"
intValueB1 = &H0
strEntryNameB2 = "MinLevel"
intValueB2 = &H10000
strEntryNameB3 = "RecommendedLevel"
intValueB3 = &H10500
strEntryNameB4 = "Flags"
intValueB4 = &Hdb
strEntryNameB5 = "1001"
intValueB5 = &H1
strEntryNameB6 = "1004"
intValueB6 = &H3
'Add more settings here as necessary. For each additional setting, another
'SetDWORDValue call must be added and another return value must be handled.

intErrors = 0
intReturnA1 = objReg.SetStringValue(HKEY_CURRENT_USER, strKeyPath, _
 strEntryNameA1, strValueA1)
If intReturnA1 = 0 Then
  WScript.Echo "Set value of " & strEntryNameA1 & " to: " & strValueA1
Else
  WScript.Echo "ERROR: Unable to set value of " & strEntryNameA1
  intErrors = intErrors + 1
End If
intReturnA2 = objReg.SetStringValue(HKEY_CURRENT_USER, strKeyPath, _
 strEntryNameA2, strValueA2)
If intReturnA2 = 0 Then
  WScript.Echo "Set value of " & strEntryNameA2 & " to: " & strValueA2
Else
  WScript.Echo "ERROR: Unable to set value of " & strEntryNameA2
  intErrors = intErrors + 1
End If
intReturnA3 = objReg.SetStringValue(HKEY_CURRENT_USER, strKeyPath, _
 strEntryNameA3, strValueA3)
If intReturnA3 = 0 Then
  WScript.Echo "Set value of " & strEntryNameA3 & " to: " & strValueA3
Else
  WScript.Echo "ERROR: Unable to set value of " & strEntryNameA3
  intErrors = intErrors + 1
End If

intReturnB1 = objReg.SetDWORDValue(HKEY_CURRENT_USER, strKeyPath, _
 strEntryNameB1, intValueB1)
If intReturnB1 = 0 Then
  WScript.Echo "Set value of " & strEntryNameB1 & " to: " & intValueB1
Else
  WScript.Echo "ERROR: Unable to set value of " & strEntryNameB1
  intErrors = intErrors + 1
End If
intReturnB2 = objReg.SetDWORDValue(HKEY_CURRENT_USER, strKeyPath, _
 strEntryNameB2, intValueB2)
If intReturnB2 = 0 Then
  WScript.Echo "Set value of " & strEntryNameB2 & " to: " & intValueB2
Else
  WScript.Echo "ERROR: Unable to set value of " & strEntryNameB2
  intErrors = intErrors + 1
End If
intReturnB3 = objReg.SetDWORDValue(HKEY_CURRENT_USER, strKeyPath, _
 strEntryNameB3, intValueB3)
If intReturnB3 = 0 Then
  WScript.Echo "Set value of " & strEntryNameB3 & " to: " & intValueB3
Else
  WScript.Echo "ERROR: Unable to set value of " & strEntryNameB3
  intErrors = intErrors + 1
End If
intReturnB4 = objReg.SetDWORDValue(HKEY_CURRENT_USER, strKeyPath, _
 strEntryNameB4, intValueB4)
If intReturnB4 = 0 Then
  WScript.Echo "Set value of " & strEntryNameB4 & " to: " & intValueB4
Else
  WScript.Echo "ERROR: Unable to set value of " & strEntryNameB4
  intErrors = intErrors + 1
End If
intReturnB5 = objReg.SetDWORDValue(HKEY_CURRENT_USER, strKeyPath, _
 strEntryNameB5, intValueB5)
If intReturnB5 = 0 Then
  WScript.Echo "Set value of " & strEntryNameB5 & " to: " & intValueB5
Else
  WScript.Echo "ERROR: Unable to set value of " & strEntryNameB5
  intErrors = intErrors + 1
End If
intReturnB6 = objReg.SetDWORDValue(HKEY_CURRENT_USER, strKeyPath, _
 strEntryNameB6, intValueB6)
If intReturnB6 = 0 Then
  WScript.Echo "Set value of " & strEntryNameB6 & " to: " & intValueB6
Else
  WScript.Echo "ERROR: Unable to set value of " & strEntryNameB6
  intErrors = intErrors + 1
End If

If intErrors = 0 Then
  WScript.Echo "Zone settings for " & strValueA1 & " successfully changed."
Else
  WScript.Echo "Unable to change all zone settings for " & strValueA1 & "."
End If

End Sub



For online peer support, join The Official Scripting Guys Forum! To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft