VBA : Internet: Ping a computer in VBA 
Options: Save as PDF | Save attached file | Toggle line numbers
| 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 |
http://msdn.microsoft.com/en-us/library/aew9yb99.aspx
http://msdn.microsoft.com/en-us/library/d6dw7aeh(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa265319(VS.60).aspx
|
Simply run the routine TestPing and you should see a message box displaying the ping results
Function sPing(sHost As String) As String
Dim oFSO As Object, oShell As Object, oTempFile As Object
Dim sLine As String, sFilename As String
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Wscript.Shell")
-
sFilename = oFSO.GetTempName
oShell.Run "cmd /c ping " & sHost & " >" & sFilename, 0, True
Set oTempFile = oFSO.OpenTextFile(sFilename, 1)
Do While oTempFile.AtEndOfStream <> True
sLine = oTempFile.Readline
sPing = sPing & Trim(sLine)
Loop
oTempFile.Close
oFSO.DeleteFile (sFilename)
End Function
Sub TestPing()
MsgBox sPing("scriptorium.serve-it.nl")
End Sub