Home > Archive > Visual Basic > March 2006 > Help! How do I get the SSID of my connection?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Help! How do I get the SSID of my connection?
|
|
| applebag 2006-03-29, 3:56 am |
| As teh topic says, I would liek to programatically get the current SSID
(any any extra information on the connection if available) from within
VB6.
>From my searches so far (I'm exhausted) I've thinking WMI is the only
way. I have been unable to find any code I can use in VB6 however. I
did find this, but I'm not very good at converting vbscript to vb6. If
someone can get this converted and working, I would appreciate it.
(Assuming it'll work in VB6.) Of any other good code will do.
Here is the vbscript :
'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_ReceivedSignalStr
engthSet, "Select *
from MSNdis_80211_ReceivedSignalStrength Where active=true")
For Each objMSNdis_80211_ReceivedSignalStrength in
objMSNdis_80211_ReceivedSignalStrengthSe
t
SigStrength =
objMSNdis_80211_ReceivedSignalStrength.Ndis80211ReceivedSignalStrength
Next
End Function
Function SigStrengthBar()
Call GetWMI(objMSNdis_80211_ReceivedSignalStr
engthSet, "Select *
from MSNdis_80211_ReceivedSignalStrength Where active=true")
For Each objMSNdis_80211_ReceivedSignalStrength in
objMSNdis_80211_ReceivedSignalStrengthSe
t
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_ReceivedSignalStr
engthSet, "Select *
from MSNdis_80211_ReceivedSignalStrength Where active=true")
For Each objMSNdis_80211_ReceivedSignalStrength in
objMSNdis_80211_ReceivedSignalStrengthSe
t
SigStrengthPercentRaw =
objMSNdis_80211_ReceivedSignalStrength.Ndis80211ReceivedSignalStrength
Next
SigStrengthPercent=(SigStrengthPercentRa
w+100)*(100/(maxstrength+100))
End Function
Function SSID()
Call GetWMI(objMSNdis_80211_ServiceSetIdentif
ierSet, "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
HUGE thanks in advance for any help!
| |
| Larry Lard 2006-03-29, 7:55 am |
|
applebag wrote:
> As teh topic says, I would liek to programatically get the current SSID
> (any any extra information on the connection if available) from within
> VB6.
>
> way. I have been unable to find any code I can use in VB6 however. I
> did find this, but I'm not very good at converting vbscript to vb6. If
> someone can get this converted and working, I would appreciate it.
> (Assuming it'll work in VB6.) Of any other good code will do.
>
> Here is the vbscript :
Put it in a module which *doesn't* have Option Explicit set. Remove the
On Error Resume Next line. Voila, it compiles. I get an automation
error when I call Function SSID, but that's presumable because I
haven't got a wireless network here. What do you get?
--
Larry Lard
Replies to group please
| |
| applebag 2006-03-29, 6:56 pm |
| Thanks Larry!
I feel like a real newbie for not thinking for that. It works great! =)
Larry Lard wrote:
> applebag wrote:
>
> Put it in a module which *doesn't* have Option Explicit set. Remove the
> On Error Resume Next line. Voila, it compiles. I get an automation
> error when I call Function SSID, but that's presumable because I
> haven't got a wireless network here. What do you get?
>
> --
> Larry Lard
> Replies to group please
| |
|
| Now put Option Explicit back into the module and declare your variables. VB
will tell you what variables aren't declared.
You should ALWAYS use Option Explicit. Removing it to fix a "problem" is
only going to result in *real* bugs. The problem you're encountering isn't
with Option Explicit. It's that you're not explicitly declaring variables
(which is what Option Explicit protects against).
No offense to Larry, but IMO that was absolutely TERRIBLE advice.
--
Mike
Microsoft MVP Visual Basic
"applebag" <applebag@gmail.com> wrote in message
news:1143665427.410178.12130@u72g2000cwu.googlegroups.com...
> Thanks Larry!
>
> I feel like a real newbie for not thinking for that. It works great! =)
>
>
> Larry Lard wrote:
>
| |
| Larry Lard 2006-03-30, 7:55 am |
| [top posting fixed]
MikeD wrote:
> "applebag" <applebag@gmail.com> wrote in message
> news:1143665427.410178.12130@u72g2000cwu.googlegroups.com...
> Now put Option Explicit back into the module and declare your variables. VB
> will tell you what variables aren't declared.
>
> You should ALWAYS use Option Explicit. Removing it to fix a "problem" is
> only going to result in *real* bugs. The problem you're encountering isn't
> with Option Explicit. It's that you're not explicitly declaring variables
> (which is what Option Explicit protects against).
>
> No offense to Larry, but IMO that was absolutely TERRIBLE advice.
Sorry, I must have missed the post where you gave him the source fixed
up to declare all the variables.
--
Larry Lard
Replies to group please
| |
|
|
"Larry Lard" <larrylard@hotmail.com> wrote in message
news:1143713562.489059.184670@v46g2000cwv.googlegroups.com...
> [top posting fixed]
>
I top-posted because applebag top-posted. It's best to follow the same
convention as was used in the message to which you're replying. Granted,
applebag didn't do that in his reply to you, but oh well. Most people don't
care if replies are top-posted or bottom-posted. What they care about is
that whatever convention is started is what is followed in subsequent
replies. Since you "fixed" the top-posting (and bottom-posted), I'm
following suit to what you did (although using inline comments as well, but
those are bottom-posted to yours). <g>
> MikeD wrote:
>
> Sorry, I must have missed the post where you gave him the source fixed
> up to declare all the variables.
>
Why should I (or anyone else, for that matter)? If you're so concerned
about actually fixing the code for him to explicitly declare variables why
didn't YOU do that instead of telling him to drop Option Explicit from the
module?
It sounds like you took offense to my comment, even though I made it a point
to mention no offense was intended. The simple truth is that was bad advice.
Sure, it took care of the problem so the code would compile, but at the cost
of potentially introducing bugs due to a stupid thing like a typo. Sorry if
you don't agree or think I was being harsh. I'm not sorry for the comment
though. When bad (or even let's just say "questionable") advice is given,
it should be pointed out.
--
Mike
Microsoft MVP Visual Basic
|
|
|
|
|