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

Cannot get a dos command to run

Status
Not open for further replies.

miteshlad2003

Technical User
Oct 25, 2003
42
GB
Dear tektips,

I am trying to put together a script that will read in a list of servers from a text file and the script will then go away and ping all the servers in the list. If servers are online it will output this into a successful file and if it receives a time out it will place the servers in a failed text file.

I am hoever having problems running the ping command. Below is what i have written so far, but i am having problems getting the ping command to fire and read from the server list.

any help would be a great help

Code so far:

Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd /c ping"
Set oShell = Nothing


Sub ReadServerData()
'Opening a file for reading
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\test\inputserverfile.txt", 1)

Do Until objFile.AtEndOfStream
ServerVariable = objFile.ReadLine
oShell.run ServerVariable
Wscript.Echo & ServerVariable
Wscript.Echo "Got Here!!"
Loop

objFile.Close
End Sub


thanks

Mitesh
 
Have you even tried a search in this forum as this topic has been covered so many times...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
going to close this thread.......

discovered a more elgant way of working:

@echo off
for /F %%i in (C:\test\inputserverfile.txt) do call :doping %%i
goto End

:doping
ping %1
if %errorlevel%==1 echo %1>>failure.txt
if %errorlevel%==0 echo %1>>success.txt
goto eof

:End


thanks

Mitesh
 
>discovered a more elgant way of working:
Elegant it may be, at least it is functional. The original vbscript is so off the mark to be of any use. So use what you understand---it is good.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top