Share via


AllowPop-wmi-multi.vbs

By The Scripting Guys, Microsoft Corporation

This script runs against multiple computers to enable popups for specific sites. It makes this change by editing the registry using the WMI System Registry provider. The default value for Windows XP Service Pack 2 is to not allow any popups.

AllowPop-wmi-multi.vbs corresponds to AllowPop.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:

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

Input for this script comes from a text file, allowpop-hosts.txt, which contains the names of computers against which the script will run.

Each line of the input file must consist of the name of a computer. Each computer must be accessible on the network and the credentials under which the script is run must have administrative privileges on it. For example:

client1
client2
server1
server2

Be sure there is no line break after the final line, as this will be interpreted by the script as an empty string.

To use the script, copy the code, paste it into Notepad, and then save the script as allowpop-wmi-multi.vbs. Then create a text file with the name of a computer on each line, as described above, and save it as allowpop-hosts.txt in the same directory as the script. To run the script, open a command prompt window to the directory of the script and type:

cscript allowpop-wmi-multi.vbs

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

Script Code

'******************************************************************************
'AllowPop-wmi-multi.vbs
'Author: Peter Costantini, the Microsoft Scripting Guys
'Date: 9/13/04
'Revision 1.0
'This script can be run against multiple computers to permit popups for 
'specific sites by editing the registry.
'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 "https://".
'The value for each site must be a binary array with one element of 0.
'The multiple computers must be specified in a text file, allowpop-hosts.txt,
'in the same directory as the script. Each line of allowpop-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
strFilename = "allowpop-hosts.txt"

'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
'Change reg entries.
    SetValues
  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

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

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 "https://"
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

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.