Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WMI Signal strenght in C++

Posted on 2008-10-16
6
Medium Priority
?
1,222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22735448
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
ID: 22736355
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
ID: 22737022
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:thisisazam
ID: 22758095
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 1500 total points
ID: 22760282
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
ID: 22914200
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 Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

604 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