View Full Version : Help with script, please


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!

one_raven
08-23-07, 02:46 AM
it's a .vbs, by the way.

one_raven
08-23-07, 05:58 AM
I did put:

strValueConf.clear

Before:

Loop

That did not make a difference.

Zephyr
08-23-07, 07:17 AM
Do strings even have a 'clear' function? Have you tried
strValueConf = ""
instead?

BTW, I'm not sure what On Error Resume Next does, but if it would allow you to use a non existent function without telling you that the function is non existent, then I wouldn't use it.

You could also try this forum (http://www.visualbasicscript.com/), but be warned, most programming forums don't appreciate unindented code (http://en.wikipedia.org/wiki/Indent_style).

leopold99
08-23-07, 10:04 AM
BTW, I'm not sure what On Error Resume Next does, . . . .
i haven't programmed in VBS but this could very well be his problem.
on error resume next, IF an error is detected the program will not halt normally.
instead it will resume execution by jumping to the NEXT statement.

i would REM the statement and try the program again.