Solved

WMI Signal strenght in C++

Posted on 2008-10-16
6
1,190 Views
Last Modified: 2008-11-13
Hi all
This is my first question in this forum
I want to find out signal strength in C++. I read about wmi. I found many script through which we can find signal strength, but unfortunately not in C++.
I wrote following code , but dont get any object in return.
---------------------------
  hres = pSvc->ExecQuery(
                  bstr_t("WQL"),                         
                  bstr_t("select Ndis80211ReceivedSignalStrength from MSNdis_80211_ReceivedSignalStrength where active=true"),            
                  WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
                  NULL,
                  &pEnumerator);
-------------------------
I dont know how to parse the output.

your help will highly appriciated.

Best Regadrs
-- Azam
0
Comment
Question by:thisisazam
  • 3
  • 3
6 Comments
 
LVL 19

Expert Comment

by:LordOfPorts
Comment Utility
Azam, I hope this will be helpful, there is a complete example with the code you have above, albeit a different query, at http://msdn.microsoft.com/en-us/library/aa390423(VS.85).aspx at the bottom of the page. I used the code after creating a new, empty Win32 console application and it works. Try using the code at the page above and replace the query with your query above and also this section where the output is displayed:

hr = pclsObj->Get(L"Ndis80211ReceivedSignalStrength", 0, &vtProp, 0, 0);

Open in new window

0
 

Author Comment

by:thisisazam
Comment Utility
Hi
Thanks for your help.
I am still having problem, let me explain more precisely.
At the bottom of the page you mentioned
http://msdn.microsoft.com/en-us/library/aa390423(VS.85).aspx
if you step 7, you find a while loop. In this loop you find
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
            &pclsObj, &uReturn);
When I write this statement with my query (for signal strength)

I get zero value for uReturn, which cause if condition true and program terminates.
if(0 == uReturn){
     break;
}

I assumed that I dont get any object in response of query.
What do you think?

Best Regards

-- Azam

--------------------------------------------------------
 while (pEnumerator)
    {
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
            &pclsObj, &uReturn);

        if(0 == uReturn)
        {
            break;
        }

        VARIANT vtProp;

        // Get the value of the Name property
        hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
        wcout << " OS Name : " << vtProp.bstrVal << endl;
        VariantClear(&vtProp);
    }

--------------------------------------------------------
0
 
LVL 19

Expert Comment

by:LordOfPorts
Comment Utility
Yes, I agree, the fourth argument of the Next method http://msdn.microsoft.com/en-us/library/aa390860(VS.85).aspx of the IEnumWbemClassObject object returns the number of objects found by the query so your query does not find any matching items. Try perhaps removing the criteria from the query to see if any objects at all are found:

select Ndis80211ReceivedSignalStrength from MSNdis_80211_ReceivedSignalStrength

The Next method will return one of the HRESULT values listed at the method reference above, try checking what the hr variable contains after the call.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:thisisazam
Comment Utility
Hi
Thanks for your help.
I found that I was using wrong namespace, so I changed it to the correct one.
But I still get zero object as a result of the query.

now my code look like
----------------------------------------
   hres = pLoc->ConnectServer(
       _bstr_t(L"root\\wmi"), // Object path of WMI namespace
         NULL,                    // User name. NULL = current user
         NULL,                    // User password. NULL = current
         0,                       // Locale. NULL indicates current
         NULL,                    // Security flags.
         0,                       // Authority (e.g. Kerberos)
         0,                       // Context object
         &pSvc                    // pointer to IWbemServices proxy
         );

MY QUERY IS

   hres = pSvc->ExecQuery(
                  bstr_t("WQL"),
                  bstr_t("SELECT * FROM MSNdis_80211_ReceivedSignalStrength"),                        
                  WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
                  NULL,
                  &pEnumerator);

   IWbemClassObject *pclsObj;
    ULONG uReturn = 0;
   while (pEnumerator){
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);

      if(0 == uReturn){
                  printf("\nNot OK\n");           // I GET THIS MESSAGE PRINTED, MEANS NO OBJECT RETURNED
            break;
        }else
                  printf("OK\n");
      
        VARIANT vtProp;

        // Get the value of the Name property
            hr = pclsObj->Get(L"Ndis80211ReceivedSignalStrength", 0, &vtProp, 0, 0);            
            printf( " Signal strength : %wS", vtProp.bstrVal);      
       
            VariantClear(&vtProp);
    }


COMMENTS?

Best Regards
-- Azam
0
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 500 total points
Comment Utility
I am unfortunately not certain, in this article http://www.microsoft.com/technet/scriptcenter/resources/qanda/mar07/hey0322.mspx that uses the same SQL query as you have above it states that it does not work on Windows Vista however they might be referring to the script (not SQL) they are using.

Another article that might be useful is at http://www.codeproject.com/KB/system/WMIInterface.aspx It is C# however it would be worth building it to check if it gives you the correct results so that you can narrow down if the problem is with the C++ code or with the query itself perhaps.

Also try changing the WMI object namespace perhaps to:

hres = pLoc->ConnectServer(_bstr_t(L"\\localhost\\root\\wmi")

This is just one of the differences I notice however I cannot say with certainty if it make a difference.

Another thought that comes to mind is that ConnectServer method http://msdn.microsoft.com/en-us/library/aa391769(VS.85).aspx returns one of the HRESULT values specifies at its link, try checking if it returns WBEM_S_NO_ERROR which what you should receive if it connected successfully.
0
 

Author Comment

by:thisisazam
Comment Utility
Hi Again after long time
I tested my code on windows XP and i was able to get signal strength.
I will higly appriciate if anyone suggest me the way to find signal strength of WLAN interface.
Waiting...
Best Regards
-- Azam
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now