' Usage
Dim value As Boolean = My.Computer.Network.Ping(hostNameOrAddress)
Dim value As Boolean = My.Computer.Network.Ping(address)
Dim value As Boolean = My.Computer.Network.Ping(hostNameOrAddress ,timeout)
Dim value As Boolean = My.Computer.Network.Ping(address ,timeout)
' Declaration
Public Function Ping( _
ByVal hostNameOrAddress As String _
) As Boolean
' -or-
Public Function Ping( _
ByVal address As System.Uri _
) As Boolean
' -or-
Public Function Ping( _
ByVal hostNameOrAddress As String, _
ByVal timeout As Integer _
) As Boolean
' -or-
Public Function Ping( _
ByVal address As System.Uri, _
ByVal timeout As Integer _
) As Boolean
Visual Basic 1 If My.Computer.Network.Ping("198.01.01.01") Then 2 MsgBox("Server pinged successfully.") 3 Else 4 MsgBox("Ping request timed out.") 5 End If 6
VB2005 01 Public Class Form1 02 Private Sub Form1_Load() Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 03 Dim strComputer As String = "." 04 Dim objWMIService As Object = GetObject("winmgmts:" _ 05 & "{impersonationLevel=impersonate}!\\" _ 06 & strComputer & "\root\cimv2") 07 Dim objStatus As Object 08 Dim colPings As Object = objWMIService.ExecQuery _ 09 ("Select * From Win32_PingStatus where Address = '61.64.127.1'") 10 11 For Each objStatus In colPings 12 If Len(objStatus.StatusCode) < 0 Or objStatus.StatusCode <> 0 Then 13 MsgBox("Computer did not respond.") 14 Else 15 MsgBox("Computer responded.") 16 End If 17 Next 18 End Sub 19 End Class