Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1227
  • Last Modified:

WMI Signal strenght in C++

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
thisisazam
Asked:
thisisazam
  • 3
  • 3
1 Solution
 
LordOfPortsCommented:
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
 
thisisazamAuthor Commented:
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
 
LordOfPortsCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
thisisazamAuthor Commented:
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
 
LordOfPortsCommented:
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
 
thisisazamAuthor Commented:
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now