AddOn-wmi-multi.vbs

作者: The Scripting Guys,Microsoft Corporation

這個指令碼在多部電腦上執行,以停用 Internet Explorer 的特定附加元件。這項變更是由使用「WMI 系統登錄」提供者來編輯登錄而達成的。您必須編輯登錄路徑,以插入要停用的附加元件正確的 CLSID。若要識別附加元件的 CLSID,請搜尋位於「管理附加元件」介面,登錄的附加元件名稱。

Addon-wmi-multi.vbs 對應於 AddOn.vbs;AddOn.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 (英文)

這個指令碼的輸入來自文字檔 addon-hosts.txt,它包含將執行指令碼的電腦名稱。

輸入檔案的每行都必須包含電腦名稱。每部電腦必須都能透過網路存取,而且指令碼用來執行的認證必須具有系統管理權限。例如:

client1 client2 server1 server2

確定最後一行後面沒有分行符號,因為指令碼會將它解譯為空字串。

若要使用指令碼,請複製程式碼並將它貼入「記事本」,再將指令碼儲存為 addon-wmi-multi.vbs。最後建立如上所述,其中每行都具有電腦名稱的文字檔,並將它儲存為和指令碼位於相同目錄的 addon-hosts.txt。若要執行指令碼,請將命令提示視窗開啟到指令碼的目錄,並輸入:

cscript addon-wmi-multi.vbs

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

指令碼


'******************************************************************************
'AddOn-wmi-multi.vbs
'Author: Peter Costantini, the Microsoft Scripting Guys
'Date: 8/25/04
'Revision 1.0
'This script can be run against multiple computers to remotely 
'disable a specific Internet Explorer add-on by editing the registry.
'You must edit the registry path to insert the correct CLSID of
'the add-on component to be disabled. To identify the CLSID of an add-on
'component, search the registry for the add-on name that is located in the
'Manage Add-ons interface.
'The multiple computers must be specified in a text file,
'addon-hosts.txt, in the same directory as the script.
'Each line of addon-hosts.txt must contain a computer name.
'Do not add a newline to the end of the last line.
'Example:
'client1
'client2
'server1
'server2
'******************************************************************************

On Error Resume Next

'Global constants and variables
Const FOR_READING = 1
Const HKEY_CURRENT_USER = &H80000001
strFilename = "addon-hosts.txt"
g_strKeyPathA = "Software\Microsoft\Windows" & _
 "\CurrentVersion\Ext\Settings\{06849E9F-C8D7-4D59-B87D-784B7D6BE0B3}"
g_strKeyPathB = "Software\Microsoft\Windows" & _
 "\CurrentVersion\Ext\Stats\{06849E9F-C8D7-4D59-B87D-784B7D6BE0B3}\iexplore"

'If text file exists, read list of hosts and operation for each.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFilename) Then
  Set objFile = objFSO.OpenTextFile(strFilename, FOR_READING)
Else
  WScript.Echo "Input file " & strFilename & " not found."
  WScript.Quit
End If
Do Until objFile.AtEndOfStream
'Get name of computer.
  strComputer = objFile.ReadLine
  Wscript.Echo VbCrLf & strComputer
  Wscript.Echo String(Len(strComputer), "-")
'Connect with WMI service and StdRegProv class.
  Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
   strComputer & "\root\default:StdRegProv")
  If Err = 0 Then
    blnCreateSubKeys = CreateSubKeys
    If blnCreateSubKeys Then
      SetValues
    End If
  Else
    WScript.Echo "ERROR: 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
Loop
objFile.Close

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

Function CreateSubKeys

intReturnA = objReg.CreateKey(HKEY_CURRENT_USER, g_strKeyPathA)
If intReturnA <> 0 Then
  WScript.Echo "ERROR: Unable to create registry path:" & VbCrLf & _
   "HKEY_CURRENT_USER\" & strKeyPathA
End If
intReturnB = objReg.CreateKey(HKEY_CURRENT_USER, g_strKeyPathB)
If intReturnB <> 0 Then
  WScript.Echo VbCrLf & "ERROR: Unable to create registry path:" & VbCrLf & _
   "HKEY_CURRENT_USER\" & strKeyPathB
End If
If (intReturnA = 0) And (intReturnB = 0) Then
  WScript.Echo VbCrLf & "Created registry subkeys:" & VbCrLf & _
   "HKEY_CURRENT_USER\" & g_strKeyPathA & VbCrLf & "HKEY_CURRENT_USER\" & _
   g_strKeyPathB
  CreateSubKeys = True
Else
  WScript.Echo "Unable to create registry subkeys."
  CreateSubKeys = False
End If

End Function

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

Sub SetValues

'Local variables
strEntryNameA1 = "Flags"
strEntryNameA2 = "Version"
intValueA1 = 1
strValueA2 = "*"
strEntryNameB1 = "Blocked"
strEntryNameB2 = "Count"
strEntryNameB3 = "Type"
strEntryNameB4 = "Time"
intValueB1 = 4
intValueB2 = &Hdf
intValueB3 = 3
arrValueB4 = Array(&Hd4, &H07, &H07, &H00, &H04, &H00, &H1d, &H00, &H0c, _
 &H00, &H20, &H00, &H2b, &H00, &H80, &H00)

intReturnA1 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathA, _
 strEntryNameA1, intValueA1)
intReturnA2 = objReg.SetStringValue(HKEY_CURRENT_USER, g_strKeyPathA, _
 strEntryNameA2, strValueA2)
If (intReturnA1 = 0) And (intReturnA2 = 0) Then
  WScript.Echo VbCrLf & "Added registry entries to:" & VbCrLf & _
   "HKEY_CURRENT_USER\" & g_strKeyPathA & VbCrLf & _
   "Entry: " & strEntryNameA1 & VbTab & "Value: " & intValueA1 & VbCrLf & _
   "Entry: " & strEntryNameA2 & VbTab & "Value: " & strValueA2
Else
  WScript.Echo VbCrLf & "ERROR: Unable to add registry entries to:" & _
   VbCrLf & "HKEY_CURRENT_USER\" & g_strKeyPathA & "."
End If

intReturnB1 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathB, _
 strEntryNameB1, intValueB1)
intReturnB2 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathB, _
 strEntryNameB2, intValueB2)
intReturnB3 = objReg.SetDWORDValue(HKEY_CURRENT_USER, g_strKeyPathB, _
 strEntryNameB3, intValueB3)
intReturnB4 = objReg.SetBinaryValue(HKEY_CURRENT_USER, g_strKeyPathB, _
 strEntryNameB4, arrValueB4)
If (intReturnB1 = 0) And (intReturnB2 = 0) And (intReturnB3 = 0) _
 And (intReturnB4 = 0) Then
  For Each Value in arrValueB4
    strValueB4 = strValueB4 & Hex(Value) & " "
  Next
  WScript.Echo VbCrLf & "Added registry entries to:" & VbCrLf & _
   "HKEY_CURRENT_USER\" & g_strKeyPathA & VbCrLf & _
   "Entry: " & strEntryNameB1 & VbTab & "Value: " & Hex(intValueB1) & _
   VbCrLf & "Entry: " & strEntryNameB2 & VbTab & "Value: " & _
   Hex(intValueB2) & VbCrLf & "Entry: " & strEntryNameB3 & VbTab & _
   "Value: " & Hex(intValueB3) & VbCrLf & "Entry: " & strEntryNameB4 & _
   VbTab & "Value: " & strValueB4
Else
  WScript.Echo VbCrLf & "ERROR: Unable to add registry entries to:" & _
   VbCrLf & "HKEY_CURRENT_USER\" & g_strKeyPathB & "."
End If

End Sub


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

免責聲明

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

顯示: