AllowPop-wmi.vbs

作者: The Scripting Guys,Microsoft Corporation

這個指令碼使用「WMI 系統登錄」提供者來編輯登錄,以啟用特定網站的快顯視窗。Windows XP Service Pack 2 的預設值不允許任何快顯視窗。

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

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

cscript allowpop-wmi.vbs

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

指令碼


'******************************************************************************
'AllowPop-wmi.vbs
'Author: Peter Costantini, the Microsoft Scripting Guys
'Date: 9/13/04
'Revision 1.0
'This script edits the registry to permit popups for specific sites.
'The default value for Windows XP Service Pack 2 is not to allow any popups.
'Each registry entry is the URL of a site without "http://".
'The value for each site must be a binary array with one element of 0.
'******************************************************************************

On Error Resume Next

'Global constants and 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
'Change reg entries.
  SetValues
Else
  WScript.Echo "Unable to connect to WMI service 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
strKeyPath = "Software\Microsoft\Internet Explorer\New Windows\Allow"
'Array of web site names, truncating "http://"
arrEntries = Array("*.technet.com", "*.msdn.com", "*.msn.com")
arrValues = Array(&H0)

'Set registry entry for each array element.
For i = 0 To UBound(arrEntries)
  intReturn = objReg.SetBinaryValue(HKEY_CURRENT_USER, strKeyPath, _
   arrEntries(i), arrValues)
  If intReturn = 0 Then
    strSites = strSites & VbCrLf & arrEntries(i)
  Else
    strErrors = strErrors & VbCrLf & arrEntries(i) & ": " & intReturn
  End If
Next
'List new registry entries and errors.
WScript.Echo "Enabled popups for the following sites:" & strSites
If Not IsEmpty(strErrors) Then
  WScript.Echo "Error: Unable to enable popups for the following sites:" & _
   strErrors
End If
'List all sites on which popups are now enabled.
WScript.Echo VbCrLf & "Popups now enabled for the following sites:"
intReturn = objReg.EnumValues(HKEY_CURRENT_USER, strKeyPath, _
   arrAllEntries, arrAllValues)
For i = 0 To UBound(arrAllEntries)
  WScript.Echo arrAllEntries(i)
Next

End Sub


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

免責聲明

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

顯示: