Windows - Unable to find WMI WiFi_AdapterAssociationInfo class

2

I am trying to execute the example at https://theroadtodelphi.wordpress.com/2011/10/15/all-about-wifi-networks-and-wifi-adapters-using-the-wmi-and-delphi/ in visual C++, wherein:

  • the WMI class WiFi_AdapterAssociationInfo is queried
  • retrieve WiFi asset information

On windows 2012 and Windows 8.1 am getting the error that unable to locate the WMI class, the code I am executing is placed below, I am getting erro code 0x80041010, please help here:

// wmiQuery.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <atlbase.h> // For ATL autorelease classes (CComBSTR, CComPtr)
#include <wbemidl.h> // For WMI
#pragma comment(lib, "wbemuuid.lib") // Link to WMI library. (Can do in library includes instead)

std::string GetOsVersionString()
{
    HRESULT hr = ::CoInitializeSecurity(NULL, -1, NULL, NULL,
    RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE,
    NULL, EOAC_NONE, NULL);

    CComPtr<IWbemLocator> pWbemLocator;
    hr = pWbemLocator.CoCreateInstance(CLSID_WbemLocator);

    CComPtr<IWbemServices> pWbemServices;
    hr = pWbemLocator->ConnectServer(CComBSTR(L"root\\cimv2"), NULL, NULL, 0, NULL, 0, NULL, &pWbemServices);

    CComPtr<IEnumWbemClassObject> pEnum;
    CComBSTR cbsQuery = L"Select Version from WiFi_AdapterAssociationInfo";
    hr = pWbemServices->ExecQuery(CComBSTR("WQL"), cbsQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);

    ULONG uObjectCount = 0;
    CComPtr<IWbemClassObject> pWmiObject;
    hr = pEnum->Next(WBEM_INFINITE, 1, &pWmiObject, &uObjectCount);

    CComVariant cvtVersion;
    hr = pWmiObject->Get(L"SSID", 0, &cvtVersion, 0, 0);

    std::string sOsVersion = CW2A(cvtVersion.bstrVal);
    return sOsVersion;
}

int _tmain(int argc, _TCHAR* argv[])
{
    HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    std::string sOsVersion = GetOsVersionString();
    ::CoUninitialize();

    return 0;
}
windows
wmi
wmi-query
visual-c++-2010
wmic
asked on Stack Overflow Aug 13, 2015 by Chandrasekhar S

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0