here is some vbscript code you can play with (save it as "ping.vbs", then run
"cscript ping.vbs" in MS-DOS, to use somewhere else, comment out lines with "wscript.echo" ):Option Explicit
  Dim rString
  rString = "127.0.0.1"  Dim Cmd
  Dim fso
  Dim cList  Cmd = "%comspec% /c ping "& rString &" -a -n 1 -w 400 > c:\temp\pingresult.txt"
  CreateObject("Wscript.Shell").Run Cmd, 0, True
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set cList = fso.OpenTextFile ("c:\temp\pingresult.txt")
 
  rString = cList.ReadAll
  WScript.Echo rString
  if instr(rString,"TTL") > 0 then
   'successful
   WScript.Echo "successful"
  else
   ' failed
   WScript.Echo "Failed"
  end if
  cList.close
  set cList = nothing  fso.GetFile("c:\temp\pingresult.txt").delete
  set fso = nothing

解决方案 »

  1.   

    有点小问题,重定向写入pingresult.txt文件时,报输入超过文件尾错误!
    %comspec% /c 是什么意思?
      

  2.   

    1.then change "pingresult.txt" to "result.txt"
    2.%comspec% /c == command.com /c 
      Executes the specified command and returns
      

  3.   

    谢谢无为,问题解决。报输入超过文件尾错误是因为cList.ReadAll
    时没有判断是否到了文件尾。加入判断后问题解决。谢谢!