1
ห้อง MS Access / : ขอโค้ดแจ้งเตือนเวลาเชื่อมต่อวงแลนไม่ได้
« เมื่อ: 17 พ.ย. 63 , 00:01:41 »
จำได้ว่ามันมีหลายแบบมาก ทั้ง api wmi แต่ที่ผมมีในเครื่องเป็นแบบง่ายๆ ไม่ได้แสดงค่าอะไรแค่ให้ค่า True กับ False เท่านั้น แต่ฟังก์ชั่นนี้ตอบสนองเร็วใช้ได้ดีกว่าการ Ping แต่แม่นยำป่าว ต้องลองดูนะครับ
Function SystemOnline(ByVal ComputerName As String) As Boolean
Dim colPingResults As Variant
Dim oPingResult As Variant
Dim strQuery As String
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & ComputerName & "'"
Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)
For Each oPingResult In colPingResults
If Not IsObject(oPingResult) Then
SystemOnline = False
ElseIf oPingResult.StatusCode = 0 Then
SystemOnline = True
Else
SystemOnline = False
End If
Next
End Function
-----------------------------------------------------
การใช้งาน
SystemOnline("192.168.1.3")
หรือ
SystemOnline("ชื่อคอมเป้าหมาย")
Function SystemOnline(ByVal ComputerName As String) As Boolean
Dim colPingResults As Variant
Dim oPingResult As Variant
Dim strQuery As String
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & ComputerName & "'"
Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)
For Each oPingResult In colPingResults
If Not IsObject(oPingResult) Then
SystemOnline = False
ElseIf oPingResult.StatusCode = 0 Then
SystemOnline = True
Else
SystemOnline = False
End If
Next
End Function
-----------------------------------------------------
การใช้งาน
SystemOnline("192.168.1.3")
หรือ
SystemOnline("ชื่อคอมเป้าหมาย")
โพสต์นี้ได้รับคำขอบคุณจาก: pondniizz