System.Management referansını ekliyoruz


PublicClass WirelessInfo
Private _InstanceName AsString
Private _Bars AsInteger

PublicProperty InstanceName() AsString
Get
Return _InstanceName
EndGet
Set(ByVal value AsString)
_InstanceName = value
EndSet
EndProperty
PublicProperty Bars() AsInteger
Get
Return _Bars
EndGet
Set(ByVal value AsInteger)
_Bars = value
EndSet
EndProperty
EndClass
PublicFunction GetWirelessSignalStrength() As List(Of WirelessInfo)

Dim searcher As ManagementObjectSearcher = Nothing
searcher = New ManagementObjectSearcher("root/WMI", "Select InstanceName,Ndis80211ReceivedSignalStrength from MSNdis_80211_ReceivedSignalStrength")
Dim adapterObjects As ManagementObjectCollection = searcher.[Get]()
Dim result AsNew List(Of WirelessInfo)()
ForEach mo As ManagementObject In adapterObjects
Dim w AsNew WirelessInfo()
w.InstanceName = mo("InstanceName").ToString()
Dim intStrength AsInteger = Convert.ToInt32(mo("Ndis80211ReceivedSignalStrengt h"))
If intStrength > -57 Then
w.Bars = 5
ElseIf intStrength > -68 Then
w.Bars = 4
ElseIf intStrength > -72 Then
w.Bars = 3
ElseIf intStrength > -80 Then
w.Bars = 2
ElseIf intStrength > -90 Then
w.Bars = 1
Else
w.Bars = 0
EndIf
result.Add(w)
Next
Return result
EndFunction