|
-
Nov 11th, 2010, 12:19 PM
#1
Thread Starter
Junior Member
Automation error
The runtime error -2147217396 (8004100c) occurs once i attempt to run this code to get the received signal strength of my WLAN card from WMI by using VB6 in Windows Vista. So is there any solution to solve this automation error ?
Private Sub Command1_Click()
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM MSNdis_80211_ReceivedSignalStrength", , 48)
For Each objItem In colItems
Text1 = objItem.Ndis80211ReceivedSignalStrength
Next
End Sub
Thanks in advance
-
Nov 12th, 2010, 03:33 AM
#2
Re: Automation error
you may need elevated privilages for this to work
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 12th, 2010, 11:10 PM
#3
Thread Starter
Junior Member
Re: Automation error
hi pete,
I got try to include dim all variables into my code, but still get runtime error in the line For Each objItem In colItems every time i debug the error.......i wonder is there any compatible or item reference issue between WMI and VB6 in Windows Vista.....So pete, can you show me your solution code here? Thanks in advance
-
Nov 12th, 2010, 11:44 PM
#4
Re: Automation error
I suspect the problem is that the query is returning an empty set of results.
Not all Wireless drivers populate the WMI classes. (The one nt the PC I'm currently using doesn't)
You may wish to try my WMIBrowser (http://www.vbforums.com/showthread.p...&highlight=wmi) to check
Last edited by Doogle; Nov 12th, 2010 at 11:47 PM.
-
Nov 13th, 2010, 01:03 AM
#5
Re: Automation error
.i wonder is there any compatible or item reference issue between WMI and VB6 in Windows Vista.
as doogle says there may be no result to display, not all wireless adaptors return results
if you search this forum you will find some threads that indicate the returned results for this class may be incorrect
as i suggested above, it may be essential to use elevated privilages, right click and run as administrator, even if you are logged in as an admin user
Last edited by westconn1; Nov 13th, 2010 at 01:28 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 13th, 2010, 01:21 AM
#6
Thread Starter
Junior Member
Re: Automation error
hi doogle, i cant run your WMI browser as it return the runtime error -2147217405 (80041003) and the debug process highlighted this line "Set WMIobjServices = GetObject(WMILOC & strNamespace)"
-
Nov 13th, 2010, 01:28 AM
#7
Thread Starter
Junior Member
Re: Automation error
westconn1, do you mean i have to right click the run as administrator of the project i created? but there is no such option but just Run option only.....
-
Nov 13th, 2010, 01:32 AM
#8
Re: Automation error
if the program is compiled to exe you can just run the exe as administrator, to run in the ide you may need to vb as administrator, then load project
this applies to doogle's program as well
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 13th, 2010, 02:54 AM
#9
Thread Starter
Junior Member
Re: Automation error
ok , i get what u mean, thanks
Last edited by Hoong; Nov 13th, 2010 at 03:02 AM.
Reason: Delete
-
Nov 13th, 2010, 03:12 AM
#10
Thread Starter
Junior Member
Re: Automation error
doogle & westconn1, i explored the WMI browser and can get the WMI MSNdis_80211_ReceivedSignalStrength class.....so thats mean my script is able to grab the signal strength (signed long) value from WMI right?
-
Nov 13th, 2010, 05:14 AM
#11
Re: Automation error
Not necessarily,the Class exists but there may not be any data to retrieve.
-
Nov 13th, 2010, 05:30 AM
#12
Re: Automation error
if it is working in doogle's browser, your script should be able to retreive the same values
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 13th, 2010, 05:35 AM
#13
Thread Starter
Junior Member
Re: Automation error
but i try many times even run VB in administration mode also got the automation error.....westconn1, what you mean by retrieve same values ya? is this the OS vista problem ?
-
Nov 13th, 2010, 05:52 AM
#14
Re: Automation error
were you able to get the values in doogle's program?
it works for me on one computer, but not another, not all return that class
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 13th, 2010, 09:57 AM
#15
Thread Starter
Junior Member
Re: Automation error
what values u mean ya? it works on XP or Vista ?
-
Nov 13th, 2010, 05:10 PM
#16
Re: Automation error
what values u mean ya? it works on XP
signal strength, did not test on vista
from the scripting guy
Note: Unfortunately, this script does not work on Windows Vista. How do you get this information on Windows Vista? Well, we’re not sure about that. But for those of you who haven’t upgraded yet, read on for an explanation of the pre-Windows Vista solution.
see http://blogs.technet.com/b/heyscript...onnection.aspx
see also
http://visual-basic.itags.org/visual-basic/215276/
keep googling wifi api
Last edited by westconn1; Nov 13th, 2010 at 05:18 PM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 14th, 2010, 01:03 AM
#17
Re: Automation error
You may be interested in some 'work in progress' that I was playing with a few months ago. It uses the WLAN API set to discover wireless network attributes, including Signal Quality. There's no user Interface as such, it just Debug.Prints the information. There's quite a few extraneous API definitions, the original performed Scans and Connected which I've stripped out, but It may help you get started.
You may need to download the API from here first: http://www.microsoft.com/downloads/e...displaylang=en (Requires a minimum of XP SP2, I can't remember whether I had to or not for Vista)
Code:
Option Explicit
Private Const DOT11_SSID_MAX_LENGTH As Long = 32
Private Const WLAN_MAX_PHY_TYPE_NUMBER As Long = 8
Private Const WLAN_NOTIFICATION_SOURCE_MOST As Long = &H7F
Private Const WLAN_NOTIFICATION_SOURCE_NONE As Long = 0
Private Type GUID
data1 As Long
data2 As Integer
data3 As Integer
data4(7) As Byte
End Type
Private Type WLAN_INTERFACE_INFO
ifGuid As GUID
InterfaceDescription(255) As Byte
IsState As Long
End Type
Private Type DOT11_SSID
uSSIDLength As Long
ucSSID(DOT11_SSID_MAX_LENGTH - 1) As Byte
End Type
Private Type WLAN_AVAILABLE_NETWORK
strProfileName(511) As Byte
dot11Ssid As DOT11_SSID
dot11BssType As Long
uNumberOfBssids As Long
bNetworkConnectable As Long
wlanNotConnectableReason As Long
uNumberOfPhyTypes As Long
dot11PhyTypes(WLAN_MAX_PHY_TYPE_NUMBER - 1) As Long
bMorePhyTypes As Long
wlanSignalQuality As Long
bSecurityEnabled As Long
dot11DefaultAuthAlgorithm As Long
dot11DefaultCipherAlgorithm As Long
dwFlags As Long
dwreserved As Long
End Type
Private Type WLAN_INTERFACE_INFO_LIST
dwNumberofItems As Long
dwIndex As Long
InterfaceInfo As WLAN_INTERFACE_INFO
End Type
Private Type WLAN_AVAILABLE_NETWORK_LIST
dwNumberofItems As Long
dwIndex As Long
Network As WLAN_AVAILABLE_NETWORK
End Type
Private Type WLAN_CONNECTION_PARAMETERS
ConnectionMode As Long
Profile As Long
pDot11Ssid As Long
pDesiredBssidList As Long
dot11BssType As Long
dwFlags As Long
End Type
Private Type WLAN_BSS_LIST
dwTotalSize As Long
dwNumberofItems As Long
wlanBssEntries As Long
End Type
Private Declare Function WlanOpenHandle Lib "wlanapi.dll" (ByVal dwClientVersion As Long, _
ByVal pdwReserved As Long, _
ByRef pdwNegotiaitedVersion As Long, _
ByRef phClientHandle As Long) As Long
Private Declare Function WlanEnumInterfaces Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
ByVal pReserved As Long, _
ppInterfaceList As Long) As Long
Private Declare Function WlanGetAvailableNetworkList Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
pInterfaceGuid As GUID, _
ByVal dwFlags As Long, _
ByVal pReserved As Long, _
ppAvailableNetworkList As Long) As Long
Private Declare Function WlanConnect Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
pInterfaceGuid As GUID, _
pConnectionParameters As WLAN_CONNECTION_PARAMETERS, _
ByVal reserved As Long) As Long
Private Declare Function WlanScan Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
pInterfaceGuid As GUID, _
pDot11Ssid As Long, _
pIeData As Long, _
reserved As Long) As Long
Private Declare Function WlanGetNetworkBssList Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
pInterfaceGui As GUID, _
ByVal pDot11Ssid As Long, _
ByVal dot11BssType As Long, _
ByVal bSecurityEnabled As Long, _
ByVal pReserved As Long, _
ppWlanBssList As WLAN_BSS_LIST) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _
Source As Any, _
ByVal Length As Long)
Private Declare Sub WlanFreeMemory Lib "wlanapi.dll" (ByVal pMemory As Long)
Private lngHandle As Long
Private Sub Command1_Click()
Dim byt() As Byte
Dim lngReturn As Long
Dim lngVersion As Long
Dim lngList As Long
Dim lngAvailable As Long
Dim lngStart As Long
Dim intCount As Integer
Dim intI As Integer
Dim strSSID As String
Dim strProfile As String
Dim udtList As WLAN_INTERFACE_INFO_LIST
Dim udtInfo As WLAN_INTERFACE_INFO
Dim udtAvailableList As WLAN_AVAILABLE_NETWORK_LIST
Dim udtNetwork As WLAN_AVAILABLE_NETWORK
Dim udtConnection As WLAN_CONNECTION_PARAMETERS
Dim udtBSS As WLAN_BSS_LIST
'
' Gwt a Handle
'
lngReturn = WlanOpenHandle(2&, 0&, lngVersion, lngHandle)
If lngReturn = 0 Then
'
' Enumerate the Network Adapters
' Get the available wireless networks
' NOTE: This code only process the first Adapter
'
lngReturn = WlanEnumInterfaces(ByVal lngHandle, 0&, lngList)
CopyMemory udtList, ByVal lngList, Len(udtList)
lngReturn = WlanGetAvailableNetworkList(lngHandle, udtList.InterfaceInfo.ifGuid, 2&, 0&, lngAvailable)
CopyMemory udtAvailableList, ByVal lngAvailable, LenB(udtAvailableList)
intCount = 0
lngStart = lngAvailable + 8
'
' Get the various attributes of each available network
' and display to the Immediate Window
'
Do
CopyMemory udtNetwork, ByVal lngStart, Len(udtNetwork)
strProfile = ByteToString(udtNetwork.strProfileName)
strProfile = Left$(strProfile, InStr(strProfile, Chr(0)) - 1)
strSSID = ByteToString(udtNetwork.dot11Ssid.ucSSID, udtNetwork.dot11Ssid.uSSIDLength, False)
strSSID = Left(strSSID, InStr(strSSID, Chr(0)) - 1)
Debug.Print "Profile "; strProfile, "SSID "; strSSID, "Signal "; udtNetwork.wlanSignalQuality; " Connected "; udtNetwork.dwFlags
Debug.Print "BSS Type "; udtNetwork.dot11BssType
Debug.Print "Number of BSSids "; udtNetwork.uNumberOfBssids
Debug.Print "Network Connectable "; udtNetwork.bNetworkConnectable
Debug.Print "Not Connectable Reason "; udtNetwork.wlanNotConnectableReason
Debug.Print "Number of PHY Types "; udtNetwork.uNumberOfPhyTypes
Debug.Print "PHY Types "
For intI = 0 To UBound(udtNetwork.dot11PhyTypes)
Debug.Print udtNetwork.dot11PhyTypes(intI); " ";
Next intI
Debug.Print
Debug.Print "More PHY Types "; udtNetwork.bMorePhyTypes
Debug.Print "Signal Quality "; udtNetwork.wlanSignalQuality
Debug.Print "Security Enabled "; udtNetwork.bSecurityEnabled
Debug.Print "Default Auth Algorithm "; udtNetwork.dot11DefaultAuthAlgorithm
Debug.Print "Default Cypher Algorithm "; udtNetwork.dot11DefaultCipherAlgorithm
Debug.Print "Connected "; udtNetwork.dwFlags
intCount = intCount + 1
lngStart = lngStart + Len(udtNetwork)
Loop Until intCount = udtAvailableList.dwNumberofItems
WlanFreeMemory lngAvailable
WlanFreeMemory lngList
Else
MsgBox "Unable to get WLAN Handle"
End If
End Sub
Private Function ByteToString(bytArray() As Byte, Optional lngLen As Long = 0, Optional boConvert As Boolean = True) As String
Dim strTemp As String
Dim intI As Integer
Dim intEnd As Integer
If lngLen = 0 Then
intEnd = UBound(bytArray)
Else
intEnd = lngLen
End If
For intI = 0 To intEnd
strTemp = strTemp & Chr(bytArray(intI))
Next intI
If boConvert = True Then strTemp = StrConv(strTemp, vbFromUnicode)
ByteToString = strTemp
End Function
Signal Quality is a number between 0 and 100 which represents the signal strength. 0 equates to an RSSI of -100dBm and 100 equates to an RSSI of -50dBm. You can calculate the RSSI equivalent of signal quality between 1 and 99 through interpolation.
Last edited by Doogle; Nov 14th, 2010 at 01:58 AM.
-
Nov 14th, 2010, 01:22 AM
#18
Re: Automation error
very nice doogle
i just pasted as is into VBA, appears to work perfectly in w7, no downloads required
shows all available networks, with signal strengths 28 to 52
i will look at the code more later, all references i saw for wifi api code, were for c++
this would be good in codebank
Last edited by westconn1; Nov 14th, 2010 at 01:27 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 14th, 2010, 02:07 AM
#19
Re: Automation error
Thanks, westconn1. I'll tidy it up a bit and re-do the bits I took out and submit to the Codebank.
-
Nov 14th, 2010, 02:11 AM
#20
Thread Starter
Junior Member
Re: Automation error
westconn1, can i know where u paste the code? i paste it into Onscript Editor ( VB script) and get compilation error
-
Nov 14th, 2010, 02:18 AM
#21
Re: Automation error
Just open a New Project in VB6 put a Command Button onto the Form and name it Command1.Then go to the Declarations section of the Form's code and past the code. It 'should' run ok if you have the APIs. If it complains about not being able to find wlanapi.dll then you'll have to download from the link I gave earlier.
-
Nov 14th, 2010, 02:23 AM
#22
Thread Starter
Junior Member
Re: Automation error
I just follow your step , and it return compile error : Only comments may appear after End Sub, End Function, or End Property. I am using Windows Vista, and the API u mentioned just now is for XP SP2 if not wrong
-
Nov 14th, 2010, 02:26 AM
#23
Re: Automation error
Are you sure you copied and pasted all (and only) the code ?
-
Nov 14th, 2010, 02:30 AM
#24
Thread Starter
Junior Member
Re: Automation error
i copy the whole code there and paste into the command declaration part , but end up with compile error that i mention just now....u know what is happening?
-
Nov 14th, 2010, 02:36 AM
#25
Re: Automation error
Paste it into the Declarations section NOT the Command1_Click
-
Nov 14th, 2010, 02:41 AM
#26
Thread Starter
Junior Member
Re: Automation error
thanks doogle, i am able to extract the WLAN info by just paste only the code ....., but i am not very understand how the code works
-
Nov 14th, 2010, 02:41 AM
#27
Re: Automation error
i paste it into Onscript Editor ( VB script) and get compilation error
this is not a scripting method, so will not work at all in a script file, i used the VBA in excel
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|