Attachments-wm-multi.vbs
By The Scripting Guys, Microsoft Corporation
This script turns off or on attachment restrictions for Outlook Express by editing the registry, using the WMI System Registry provider. It can run against a local or remote computer.
Attachments-wmi-multi.vbs corresponds to Attachments.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:
Input for this script comes from a comma-delimited text file, dcomsec-hosts.csv, which contains the names of computers against which the script will run and the GUID of the application to exempt for each one. This text file must be in the same folder as the script.
Each line of the input file must consist of a computer name, a comma, and either a 1 or a 0, with no spaces before or after the comma: 1 turns restrictions on; 0 turns restrictions off. 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,1
client2,0
server1,1
server2,0
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 Attachments-wmi-multi.vbs. To run the script, open a command prompt window to the directory of the script and type:
cscript attachments-wmi-multi.vbs
If the default script host on the computer is Cscript.exe, the initial "cscript" may be omitted.
Script Code
'******************************************************************************
'Attachments-wmi-multi.vbs
'Author: Peter Costantini, the Microsoft Scripting Guys
'Date: 8/24/04
'Revision 1.0
'This script can be run against multiple computers to remotely edit
'the registry to turn off or on attachment restrictions for Outlook Express.
'1 turns restrictions on.
'0 turns restrictions off.
'The multiple computers must be specified in a comma-delimited
'text file, attach-hosts.csv, in the same directory as the script.
'Each line of attach-hosts.csv must have a computer name followed
'by a comma, followed by either a 1 or a 0.
'Do not add a newline to the end of the last line.
'Example (turn restriction on for client1 & server1,
'turn restrictions off for client2 and server2):
'client1,1
'client2,0
'server1,1
'server2,0
'******************************************************************************
On Error Resume Next
'Global constants and variables
Const FOR_READING = 1
Const HKEY_CURRENT_USER = &H80000001
g_strKeyPath = "Identities"
strFilename = "attach-hosts.csv"
'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
strHost = objFile.ReadLine
arrHost = Split(strHost, ",")
'Get name of computer.
strComputer = arrHost(0)
'Get value for attachment restrictions.
g_intValue = arrHost(1)
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
g_strID = GetID
If IsEmpty(g_strID) Then
WScript.Echo "ERROR: Unable to obtain default user ID."
Else
SetValue
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 GetID
'Local variables
strEntryName1 = "Default User ID"
intReturn = objReg.GetStringValue(HKEY_CURRENT_USER, g_strKeyPath, _
strEntryName1, strValue)
If intReturn = 0 Then
GetID = strValue
Else
GetID = ""
End If
End Function
'******************************************************************************
Sub SetValue
'Local variables
strKeyPath2 = g_strKeyPath & "\" & g_strID & "\Software\Microsoft" & _
"\Outlook Express\5.0\Mail"
strEntryName2 = "Safe Attachments"
intReturn = objReg.SetDWORDValue(HKEY_CURRENT_USER, strKeyPath2, _
strEntryName2, g_intValue)
If intReturn = 0 Then
WScript.Echo "Changed value of " & strEntryName2 & " to " & g_intValue & "."
If g_intValue = 0 Then
WScript.Echo "Turned attachment restrictions off."
Else
WScript.Echo "Turned attachment restrictions on."
End If
Else
WScript.Echo "ERROR: Unable to change value of " & strEntryName2 & "."
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.