Option Explicit
Public WiFiHardwareName As String, WiFiDecibals As Long
Dim objWMIService As Object, isSet As Boolean
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Public Enum ConnectedState
INTERNET_CONNECTION_MODEM = &H1
INTERNET_CONNECTION_LAN = &H2
INTERNET_CONNECTION_PROXY = &H4
INTERNET_CONNECTION_MODEM_BUSY = &H8
INTERNET_RAS_INSTALLED = &H10
INTERNET_CONNECTION_OFFLINE = &H20
INTERNET_CONNECTION_CONFIGURED = &H40
End Enum
Public Function WifiSignalStrength(Optional Computer As String = ".") As Long
On Error Resume Next
Dim colItems As Object, objItem As Object
WifiSignalStrength = IIf(isConnected, 5, 0)
If Not isSet Then
Set objWMIService = GetObject("winmgmts:" & Computer & "rootwmi")
isSet = True
End If
Set colItems = objWMIService.ExecQuery("Select * From MSNdis_80211_ReceivedSignalStrength")
For Each objItem In colItems
WiFiDecibals = objItem.NDIS80211ReceivedSignalStrength
WiFiHardwareName = objItem.InstanceName
Select Case WiFiDecibals
Case 0: WiFiHardwareName = "Ethernet"
Case Is > -57: WifiSignalStrength = 5
Case Is > -68: WifiSignalStrength = 4
Case Is > -72: WifiSignalStrength = 3
Case Is > -80: WifiSignalStrength = 2
Case Is > -90: WifiSignalStrength = 1
Case Else: WifiSignalStrength = 0
End Select
Next
End Function