Partager via


RpcSec-wmi-multi.vbs

By The Scripting Guys, Microsoft Corporation

This script configures RPC security to bypass new restrictions in Windows XP Service Pack 2 and allow anonymous call back. It performs this task by editing the registry, using the WMI System Registry provider. It can run against multiple computers.

RpcSec-wmi-multi.vbs corresponds to RpcSec.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 comma-delimited text file, rpcsec-hosts.csv, which contains the name of the computers against which the script will run and a parameter for it. This text file must be in the same folder as the script. Each computer must be accessible on the network and the credentials under which the script is run must have administrative privileges on it.

Valid values for the parameter (RestrictRemoteClients) are as follows:
0 = Bypasses new restrictions.
1 = Restricts access to all RPC interfaces but allows anonymous callbacks.
2 = Restricts access to all RPC interfaces and does not allow anonymous callbacks.

Each line of the input file must consist of a computer name, a comma, and the integer 0, 1, or 2, with no spaces before or after the comma.For example :

client1,0
server1,1
client2,0
server2,2

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 RpcSec-wmi-multi.vbs. To run the script, open a command prompt window to the directory of the script and type:

cscript rpcsec-wmi-multi.vbs

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

Script Code

'******************************************************************************
'RpcSec-wmi-multi.vbs
'Author: Peter Costantini, the Microsoft Scripting Guys
'Date: 8/25/04
'Revision 1.0
'System requirement: Windows XP Service Pack 2.
'This script configures RPC security to bypass new restrictions in Windows XP
'Service Pack 2 and allow anonymous call back.
'It can be run against multiple local or remote computers.
'The multiple computers must be specified in a comma-delimited
'text file, rpcsec-hosts.csv, in the same directory as the script.
'Each line of rpcsec-hosts.csv must have a computer name followed by a comma,
'followed by an integer from 0 through 2.
'Do not add a newline to the end of the last line.
'Example (bypass on client1 & server1, restrict access but allow anon
'callbacks on client2, and restrict access and do not allow anon callbacks
'on server2):
'client1,0
'client2,1
'server1,0
'server2,2
'Valid RestrictRemoteClients values are as follows:
'0 = Bypasses new restrictions.
'1 = Restricts access to all RPC interfaces but allows anonymous callbacks.
'2 = Restricts access to all RPC interfaces and does not allow anonymous
'callbacks.
'******************************************************************************

On Error Resume Next

Const FOR_READING = 1
strFilename = "rpcsec-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)
'DWORD value of RestrictRemoteClients for this host.
  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
    SetValue
  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
Loop
objFile.Close

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

Sub SetValue

Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Policies\Microsoft\Windows NT\RPC"
strEntryName = "RestrictRemoteClients"
intValue = 0

intReturn = objReg.CreateKey(HKEY_LOCAL_MACHINE, strKeyPath)
If intReturn = 0 Then
  WScript.Echo "Created registry subkey " & strKeyPath & _
   ". If it previously existed, did not overwrite existing values."
  intReturn = objReg.SetDWORDValue(HKEY_LOCAL_MACHINE, strKeyPath, _
   strEntryName, intValue)
  If intReturn = 0 Then
    WScript.Echo "Changed value of " & strEntryName & " to " & intValue
  Else
    WScript.Echo "ERROR: Unable to change value of " & strEntryName
  End If
Else
  WScript.Echo "ERROR: Unable to create registry path " & _
   strKeyPath
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.