Hi, I have created a script to update the SNMP Location in each server. The script reads the servers from a text file, then connect to each one and update the location through the registry. The script works very well on Windows 2003 servers, but I can't get it to work on Windows 2000 Servers. Thanks in advanced!!!
This is the one that works very well in Windows 2003.
On Error Resume Next
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("\\pl1web01\NTSG\Windows_Utilities\SNMP_Change\PR01\servers.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
Const HKEY_LOCAL_MACHINE = &H80000002
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\RFC1156Agent\"
strValueName = "sysLocation"
strValue = "PR1/PC02/2"
strKeyPath = "SYSTEM\ControlSet001\Services\SNMP\Parameters\RFC1156Agent\"
strValueName = "sysLocation"
strValue = "PR1/PC02/2"
strKeyPath = "SYSTEM\ControlSet002\Services\SNMP\Parameters\RFC1156Agent\"
strValueName = "sysLocation"
strValue = "PR1/PC02/2"
Return = objReg.SetStringValue( _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue)
If (Return = 0) And (Err.Number = 0) Then
Wscript.Echo strKeyPath & _
strValue
Else
Wscript.Echo "SetStringValue failed. Error = " & Err.Number
End If
Loop
objTextFile.Close
This is the one that works very well in Windows 2003.
On Error Resume Next
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("\\pl1web01\NTSG\Windows_Utilities\SNMP_Change\PR01\servers.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
Const HKEY_LOCAL_MACHINE = &H80000002
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Services\SNMP\Parameters\RFC1156Agent\"
strValueName = "sysLocation"
strValue = "PR1/PC02/2"
strKeyPath = "SYSTEM\ControlSet001\Services\SNMP\Parameters\RFC1156Agent\"
strValueName = "sysLocation"
strValue = "PR1/PC02/2"
strKeyPath = "SYSTEM\ControlSet002\Services\SNMP\Parameters\RFC1156Agent\"
strValueName = "sysLocation"
strValue = "PR1/PC02/2"
Return = objReg.SetStringValue( _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue)
If (Return = 0) And (Err.Number = 0) Then
Wscript.Echo strKeyPath & _
strValue
Else
Wscript.Echo "SetStringValue failed. Error = " & Err.Number
End If
Loop
objTextFile.Close