Scriptorium

us fr nl




VBA : Internet: Ping a computer in VBA   nl


Options: Save as PDF | Save attached file | Toggle line numbers

Details:

Type: function
Added By: Rembo
Short Description:
Windows Scripting is a very powerful tool to work with a network. You can do many things with it. This example demonstrates the usage of the Shell and FileSystem object to do a ping to a server on the internet.
Notes:
In this example I used late binding. If you want to use early binding you'll have to set a reference to the Microsoft Scripting Runtime library.
Added: Feb 6 2009 at 3:15 PM
Related URLs


Usage:

Simply run the routine TestPing and you should see a message box displaying the ping results


Code:

Formatted | Unformatted
  1. Function sPing(sHost As String) As String
  2.  
  3. Dim oFSO As Object, oShell As Object, oTempFile As Object
  4. Dim sLine As String, sFilename As String
  5.  
  6. Set oFSO = CreateObject("Scripting.FileSystemObject")
  7. Set oShell = CreateObject("Wscript.Shell")
  8. sFilename = oFSO.GetTempName
  9. oShell.Run "cmd /c ping " & sHost & " >" & sFilename, 0, True
  10. Set oTempFile = oFSO.OpenTextFile(sFilename, 1)
  11.  
  12. Do While oTempFile.AtEndOfStream <> True
  13. sLine = oTempFile.Readline
  14. sPing = sPing & Trim(sLine)
  15. Loop
  16. oTempFile.Close
  17. oFSO.DeleteFile (sFilename)
  18. End Function
  19.  
  20. Sub TestPing()
  21. MsgBox sPing("scriptorium.serve-it.nl")
  22. End Sub



User comments :

Add a new comment   Back to Top
Atom Feed
Contact | About This Application | Scriptorium Website