- VB,VBA
- 2009-12-10 - 更新:2018-12-26
Private Sub Example() If PingResult("192.168.1.1") = False Then MsgBox "PCが起動していません。" Else MsgBox "PCは起動しています。" End If End Sub Function PingResult(strHostname As String) Dim objWMIService As Object, objStatus As Variant Set objWMIService = _ GetObject("winmgmts:{impersonationLevel=impersonate}"). _ ExecQuery("select * from Win32_PingStatus where address = '" & _ strHostname & "'", , 48) For Each objStatus In objWMIService If IsNull(objStatus.StatusCode) Or objStatus.StatusCode <> 0 Then PingResult = False Else PingResult = True End If Next End Function
7,339 views