Zones-wmi.vbs

作者: The Scripting Guys,Microsoft Corporation

這個指令碼使用「WMI 系統登錄」提供者來編輯登錄,以設定特定 Internet Explorer 安全性區域的設定。它可以在本機或遠端電腦上執行。

相關的安全性區域由路徑中 Zones 之下的子機碼數值所表示:

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

其中 x 表示:

0 = 本機電腦
1 = 內部網路
2 = 信任的網站
3 = 網際網路
4 = 限制的網站

您可以在變數 strKeyPath 中變更這個值,以設定不同的區域。

Zones-wmi.vb 對應於 Zones.vbs,Zones.vbs 是《Application Compatibility Testing and Mitigation Guide for Windows XP Service Pack 2》(Windows XP Service Pack 2 應用程式相容性測試及緩和指南) 隨附的指令碼之一,並記錄在<附錄>中。您可以下載用來安裝該指南及其相關指令碼的 Windows Installer (.msi) 檔案,網址是:

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

若要使用指令碼,請複製程式碼並將內容貼到「記事本」,再將指令碼儲存為 Zones-wmi.vbs。若要執行指令碼,請將命令提示視窗開啟到指令碼的目錄,並輸入:

cscript zones-wmi.vbs

如果電腦上的預設指令碼裝載是 Cscript.exe,就可以省略開頭的 cscript。

指令碼


'******************************************************************************
'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


如需線上對等支援,請加入 msnews.microsoft.com 新聞伺服器上的 microsoft.public.windows.server.scripting (英文) 社群。若您想要對範例指令碼或指令碼指南,提供意見、回報問題,請與 Microsoft TechNet (英文) 連絡。

免責聲明

此範例指令碼不支援任何 Microsoft 標準技術支援方案或服務。上述的範例指令碼係依「現況」提供,不附帶任何擔保。Microsoft 公司不提供任何的默示擔保,包括但不限於任何商業適售性及特定用途之適用性的默示擔保。您必須承擔此範例指令碼或文件所造成的一切風險。在任何情況下,無論是使用或無法使用此範例指令碼或文件所造成的損害 (包括但不限於營業之損失、營業之中斷、營業資訊之滅失及其他金錢損失),Microsoft 公司、作者群或此指令碼之創作、製造或散發有關之人員概不負責,即使 Microsoft 已經被告知損害發生之可能性亦同。

顯示: