one_raven
08-23-07, 02:45 AM
Here's the script:
On Error Resume Next
Const FOR_READING = 1
strHostFile = "servers.txt"
'Read computer names for install from text file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strHostFile) Then
Set objTextStream = objFSO.OpenTextFile(strHostFile, FOR_READING)
Else
WScript.Echo "Input file " & strHostFile & " not found."
WScript.Quit
End If
Do Until objTextStream.AtEndOfStream
strComputer = objTextStream.ReadLine
HIVE = &H80000002
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control"
objReg.CreateKey HIVE, strKeyPath
ValueName = "Testing"
strValue = "Test Value for Insertion"
objReg.SetStringValue HIVE, strKeyPath, ValueName, strValue
'strValueConf.clear
'Create log file
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFile = objFS.CreateTextFile ("output.log")
objReg.GetStringValue HIVE, strKeyPath, ValueName, strValueConf
ObjNewFile.WriteLine "SystemName: " & strcomputer
ObjNewFile.WriteLine strValueConf
ObjNewFile.WriteLine
Loop
Wscript.Echo "Done"
It should read a list of server names from a flat file called "servers.txt".
For each of the servers listed in the file, it should create a registry key under HKLM\System\CurrentControlSet\Control named "Testing" and insert the string value "Test Value for Insertion".
This all works fine.
Next, for verification, it should read the value in the key it just created, and output it into a log file.
That also works.
One problem, though...
I created a list of servers with two fake server names in it, and the local machine in the middle.
The output I would expect to see in the log is:
SystemName: FakeServerName1
SystemName: .
Test Value for Insertion
SystemName: FakeServerName2
Instead I see:
SystemName: FakeServerName1
SystemName: .
Test Value for Insertion
SystemName: FakeServerName2
Test Value for Insertion
Why is it holding onto the strValueConf variable when it can not connect to the requested server?
I can't figure it out!
On Error Resume Next
Const FOR_READING = 1
strHostFile = "servers.txt"
'Read computer names for install from text file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strHostFile) Then
Set objTextStream = objFSO.OpenTextFile(strHostFile, FOR_READING)
Else
WScript.Echo "Input file " & strHostFile & " not found."
WScript.Quit
End If
Do Until objTextStream.AtEndOfStream
strComputer = objTextStream.ReadLine
HIVE = &H80000002
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control"
objReg.CreateKey HIVE, strKeyPath
ValueName = "Testing"
strValue = "Test Value for Insertion"
objReg.SetStringValue HIVE, strKeyPath, ValueName, strValue
'strValueConf.clear
'Create log file
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFile = objFS.CreateTextFile ("output.log")
objReg.GetStringValue HIVE, strKeyPath, ValueName, strValueConf
ObjNewFile.WriteLine "SystemName: " & strcomputer
ObjNewFile.WriteLine strValueConf
ObjNewFile.WriteLine
Loop
Wscript.Echo "Done"
It should read a list of server names from a flat file called "servers.txt".
For each of the servers listed in the file, it should create a registry key under HKLM\System\CurrentControlSet\Control named "Testing" and insert the string value "Test Value for Insertion".
This all works fine.
Next, for verification, it should read the value in the key it just created, and output it into a log file.
That also works.
One problem, though...
I created a list of servers with two fake server names in it, and the local machine in the middle.
The output I would expect to see in the log is:
SystemName: FakeServerName1
SystemName: .
Test Value for Insertion
SystemName: FakeServerName2
Instead I see:
SystemName: FakeServerName1
SystemName: .
Test Value for Insertion
SystemName: FakeServerName2
Test Value for Insertion
Why is it holding onto the strValueConf variable when it can not connect to the requested server?
I can't figure it out!