Private Sub Form_Load()
Dim i As Integer
i = PingSilent(txtClientName.Value)
If i = 0 Then
lblPing.BackColor = vbRed
ElseIf i = 1 Then
lblPing.BackColor = vbGreen
Else
lblPing.BackColor = vbYellow
End If
End Sub
Function PingSilent(strComputer)
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus where address = '" _
& strComputer & "'")
For Each objStatus In objPing
If IsNull(objStatus.StatusCode) Or objStatus.StatusCode <> 0 Then
PingSilent = 0
Else
PingSilent = 1
End If
Next
End Function
|