Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop Issue

Status
Not open for further replies.

Ednetman

Technical User
May 20, 2002
54
US

I have a script to check file versions, but I am havig problems with the loop. make a few edits to it and it will loop, but only to the first line of the text file. Then it runs untill I kill it, or I can make a few other changes and get an error that I used a loop without a DO command. I can't figure that one out since the DO command is on line 13 of the script.

Can someone take a look at this for me and see what I am overlooking. I'm sure it is something simple, but I'm not seeing because I've been looking at the screen for two many hours.

---------------------------------------------------------------

' =====================================================
' Code to read computer name from a text file
' =====================================================

On Error Resume Next

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\scripts\WSH.txt", ForReading)

Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine

' =========================================================
' Code to check file version on remote machines
' =========================================================

Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("SELECT * FROM CIM_DataFile WHERE Name = 'C:\\winnt\\system32\\wscript.exe'")
For Each objFile in colFiles

' =======================================================
' Code to write output to a file
' =======================================================
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\scripts\output.txt", ForAppending, True)
objTextFile.WriteLine("Computer: " & strComputer & vbTab & _
"WSH Version: " & objFile.Version)

Next

' =======================================================
' End
' =======================================================

Loop

objTextFile.Close
WScript.Echo "Script Complete! Check in C:\scripts\output.txt for your results."

---------------------------------------------------------------

I have a folder created with the output.txt and wsh.txt in it.
 
you re-use your objTextFile variable, it is controlling the do loop and should not then be used for the output.txt..

on top of that

' =======================================================
' Code to write output to a file
' =======================================================
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\scripts\output.txt", ForAppending, True)


should be placed outside of the For Next and outside of the Do Loop, this will speed things up no end
 
Note that it's named poorly too. Opening a textfile returns a TextStream object, not a File object.
 
Hey dilettante,

Thanks for the info. I actually copied that portion of the script from the Microsoft Scripting Center. No original code there, I just changed the file name (I even left the path the same!)

mrmovie,

Thanks for the advice, I knew it had to be something simple I was overlooking. I'm going to try it out and I'll let you know if it worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top