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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a Computer Name, read from a file into a do while loop

Status
Not open for further replies.

BumpBump

Technical User
Sep 9, 2004
5
US
Here is my issue.
I can read from the file:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReadFile = objFSO.OpenTextFile("C:\anyname.txt", ForReading)
strComputer = objReadFile.ReadLine
Set objTextFile = objFSO.OpenTextFile("C:path\"&strComputer&".htm", ForWriting, True)
Do While objReadFile.AtEndOfStream = False
strComputer = objReadFile.ReadLine
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service",,48)
wscript.echo objItem.SystemName
Loop

Here is the issue:
If I take out the first strComputer = bjReadFile.ReadLine the script works fine. If however I do use that first strComputer = objReadFile.ReadLine, the whole script produces nothing.
How can I use the read computer name to create a file with that name and use that computer name in my queries?

 
put the
Set objTextFile = objFSO.OpenTextFile("C:path\"&strComputer&".htm", ForWriting, True)
into the do loop

Do While objReadFile.AtEndOfStream = False
strComputer = objReadFile.ReadLine
Set objTextFile = objFSO.OpenTextFile("C:path\"&strComputer&".htm", ForWriting, True)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service",,48)
wscript.echo objItem.SystemName
objTextFile.Close
Set objTextFile = Nothing
Loop


i dont get the
objItem.SystemName
I cant see an objItem anywhere
 
perhaps you should be doing another loop

For Each objItem In colItems
objTextFIle.WriteLine objItem.SystemName
Next

???
 
when setting

Set objTextFile = objFSO.OpenTextFile("C:path\"&strComputer&".htm", ForWriting, True)

is the objTextFile simply a pointer and objFSO being set to the file?

If so then you are reseting the ojbFSO object when you are defining a new pointer to it and opening a different file when you open the file on the remote computer.

I am only guessing being that I am fairly new to vbscript also.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top