Solved Help reading columns in a csv file with vbs

November 15, 2012 at 15:53:15
Specs: Windows 7
Here is my present script. it reads a single column file of ip addresses and pings each one.
I'd like to have 2 columns in a csv file. ip address,hostname Have it ping the ip, but print the hostname. Your help would be greatly appreciated.


Set InputFile = fso.OpenTextFile("h:\usr\bin\MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
HostName = InputFile.ReadLine
Set WshShell = WScript.CreateObject("WScript.Shell")
Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)
objExcel.Cells(intRow, 1).Value = UCase(HostName)
Select Case Ping
Case 0 objExcel.Cells(intRow, 2).Value = "On Line"
Case 1 objExcel.Cells(intRow, 2).Value = "Off Line"
End Select



See More: Help reading columns in a csv file with vbs

Report •


#1
November 15, 2012 at 18:09:10
✔ Best Answer
set fso...
Set WshShell...
Set InputFile = fso.OpenTextFile("h:\usr\bin\MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
iline=split(inputFile.ReadLine,",")
Ping = WshShell.Run("ping -n 1 " & iline(0), 0, True)
objExcel.Cells(intRow, 1).Value = UCase(iline(1))
if Ping=0 then z="On" else z="Off"
objExcel.Cells(introw,2).value=z&" Line"
'===== end

I put the "createobject" outside the loop for efficiency. Note that ping (on win-7) gives the computer name in its output if you use the -a option, in the first line, second token, then you would not need to maintain the cross-reference, but then you need to capture the ping data.


Report •

#2
November 16, 2012 at 06:55:28
Worked great. Thanks so much. Split - that's the ticket. Again thank you.

Report •

#3
November 16, 2012 at 07:36:46
If you're pinging from VBScript, I suggest you use WMI instead.
Set ping = GetObject("winmgmts:Win32_PingStatus.Address='" & addr & "'")
WScript.Echo ping.StatusCode & " - " & ping.ResponseTime

How To Ask Questions The Smart Way


Report •

Related Solutions


Ask Question