Function Pings(strMachines As String) As Boolean
aMachines = Split(strMachines, ";")
Pings = True
For Each machine In aMachines
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & machine & "'")
For Each objStatus In objPing
If IsNull(objStatus.StatusCode) Or objStatus.StatusCode <> 0 Then
Debug.Print ("machine " & machine & " is not reachable")
Pings = Pings And False
Else
Pings = Pings And True
End If
Next
Next
End Function
If Pings("计算机1的IP") Then MsgBox "计算机1在线。"
If Pings("计算机2的IP") Then MsgBox "计算机2在线。"