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!

Problem with Ping

Status
Not open for further replies.

NetNodeMan

Technical User
Mar 30, 2005
65
IE
I have the following code which I want to use to ping a number of servers:

Dim Shell, PingExec, PingOutput,Wshshell, SystemPath, Result, Server

SystemPath="C:\winnt\system32"
'set shell = server.createobject("wscript.shell")

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\srvinfo\test.txt", ForReading, True)
server = objTextFile.ReadLine

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
oShell.Run "command /C ping.exe " & Server & "> Ping.txt"

Wscript.echo Result
Wscript.Echo server
objTextFile.close


Wscript.Quit

What I actually want to do is to run a srvinfo rather than a ping. The result of this srvinfo would then be written to a file which would be updated each day i.e. the log file would have a daily timestamp on it. I have this working for one server and it writes to Ping.txt but how do I do this for multiple servers and multiple outputs?

Thanks in advance.
 
'slight improvement, dare i say it on PHV's code
'this way you get different output file for each server
'not that you asked for it

oShell.Run "your srvinfo call here >> " & server & ".txt"

I would also be tempted to use Option Explicit and Dim your variables.
I would include 'server = ""' into

While Not objTextFile.AtEndOfStream
server = ""
server = objTextFile.ReadLine
WScript.Echo server

:whilst i dont believe .ReadLine method would actually fail but if it did you might end up with a dodgy value of server left over from the last loop pass

I would also include

Set objTextFile = Nothing
Set WshShell = Nothing
Set FSO = Nothing

:before the Wscirpt.Quit
I know the trash collected will handle this for you but i think it is good coding practice

to be totally anal i would prob also do a FSO.FileExists on your "c:\srvinfo\test.txt" before trying to open the file

PHV was probably in too much of a hurry going to MVP of the month to include all this ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top