Solved

WMI Signal strenght in C++

Posted on 2008-10-16
6
1,195 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

948 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

18 Experts available now in Live!

Get 1:1 Help Now