'Wireless Signal Strength

'Sigstrength and SSID: Copyright 2004, David Wheeler drwheeler@lycos.com

'SigStrengthBar and SigStrengthPercent added by Hans Heigenhauser hans@heigenhauser.net 20.06.2004

'Not redistributable without express permission from authors.

'SigStrength determines the Signalstrength of a WLAN-Connection via WMI. It returns a negative number which decreases with loss of
'Signalstrength. i.e. -50 is better than -80. The correspinding WMI-function is not included in the WMI-Meters of Samurize.

'SSID determines the Service Identifier Set (or "WLAN-Name") of the WLAN you are connected to via WMI.The correspinding WMI-function
'is not included in the WMI-Meters of Samurize.

'SigStrengthBar simulates the original display of the Windows XP Wireless Network Status Display with only 5 possible signal 
'strengths. The values that determine the display were gathered by simple trial and may vary a little bit from the display windows
'provides, although I don't think they do.

'SigStrengthPercent returns a percentage of the maximal reachable signalstrength. The Constant "maxstrength" was gathered by 
'trial in a distance of 20cm from my receiver and can be changed by changing the value of the constant after this lines. 
'The value for your system can be determined with the function "SigStrength". Just change the place of your System until
'you have found the maximum value of SigStrenth (this would be the lowest negative number, as described in the description of 
'SigStrength)

const maxstrength = -30

on error resume Next

Private Sub GetWMI(WMIArray, WMIQuery)
   Set WMIClass = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\wmi")
   Set WMIArray = WMIClass.ExecQuery(WMIQuery)
End Sub

Function SigStrength()
   Call GetWMI(objMSNdis_80211_ReceivedSignalStrengthSet, "Select * from MSNdis_80211_ReceivedSignalStrength Where active=true")
   For Each objMSNdis_80211_ReceivedSignalStrength in objMSNdis_80211_ReceivedSignalStrengthSet
       SigStrength = objMSNdis_80211_ReceivedSignalStrength.Ndis80211ReceivedSignalStrength
   Next
End Function


Function SigStrengthBar()
   Call GetWMI(objMSNdis_80211_ReceivedSignalStrengthSet, "Select * from MSNdis_80211_ReceivedSignalStrength Where active=true")

   For Each objMSNdis_80211_ReceivedSignalStrength in objMSNdis_80211_ReceivedSignalStrengthSet
       SigStrengthBarRaw = objMSNdis_80211_ReceivedSignalStrength.Ndis80211ReceivedSignalStrength
   Next
   SigStrengthBar=0
   If SigStrengthBarRaw > -57 Then 
    SigStrengthBar=5
   ElseIf SigStrengthBarRaw > -68 Then 
    SigStrengthBar=4
   ElseIf SigStrengthBarRaw > -72 Then 
    SigStrengthBar=3
   ElseIf SigStrengthBarRaw > -80 Then 
    SigStrengthBar=2
   ElseIf SigStrengthBarRaw > -90 Then
    SigStrengthBar=1
   End If

End Function


Function SigStrengthPercent()
   Call GetWMI(objMSNdis_80211_ReceivedSignalStrengthSet, "Select * from MSNdis_80211_ReceivedSignalStrength Where active=true")

   For Each objMSNdis_80211_ReceivedSignalStrength in objMSNdis_80211_ReceivedSignalStrengthSet
       SigStrengthPercentRaw = objMSNdis_80211_ReceivedSignalStrength.Ndis80211ReceivedSignalStrength
   Next
   SigStrengthPercent=(SigStrengthPercentRaw+100)*(100/(maxstrength+100))

End Function

Function SSID()
   Call GetWMI(objMSNdis_80211_ServiceSetIdentifierSet, "Select * from MSNdis_80211_ServiceSetIdentifier Where active=true")

   For Each objMSNdis_80211_ServiceSetIdentifier in objMSNdis_80211_ServiceSetIdentifierSet
       ID = ""
       For i = 0 to objMSNdis_80211_ServiceSetIdentifier.Ndis80211SsId(0)
         ID = ID & chr(objMSNdis_80211_ServiceSetIdentifier.Ndis80211SsId(i + 4))
       Next
       SSID = ID
   Next
End Function