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;
}
  • In order to work with these WMI classes your Wifi Network adapter must install a CIMWiFiProvider which implement these classes. – RRUZ Aug 14 '15 at 01:31
  • I searched in google for CIMWiFiProvider but, I can't able to find out. Please let me know where can i find and install it – Chandrasekhar S Aug 17 '15 at 08:31
  • The `CIMWiFiProvider` is installed when you install the drivers of you network adapter, so you must check if the vendor of the network card include this WMI provider, otherwise you must use the [native wifi](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706556(v=vs.85).aspx). – RRUZ Aug 17 '15 at 15:43

0 Answers0