Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting IP Address through WMI

Getting IP Address through WMI

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++questiondatabase
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qrverona
    wrote on last edited by
    #1

    Dear all, I'm writing a C++ (.NET 2003 with MFC) application that needs to query several data through WMI. I have a problem while accessing to the "IPAddress" data managed by the Win32_NetworkAdapterConfiguration WMI class. It is stored as a string array, the first Get returns me this information, but I did not found any issue on how to get the array. bool CMyDoc::GetWMIItemValue( IWbemClassObject *pInstance, LPCWSTR pItemName, CStringArray& strArray) { VARIANT val; LONG lFlavour; HRESULT hGet; CIMTYPE cimType; VariantInit(&val); strArray.RemoveAll(); hGet = pInstance->Get( pItemName, 0, &val, // val cannot hold the result &cimType, // returns 2008 = string array &lFlavour); // returns 0 if (hGet == WBEM_S_NO_ERROR) { if (cimType == (CIM_STRING | CIM_FLAG_ARRAY)) { // val holds 0x2008 too, unusable // how can I access the array? } } Thank you for you help... PS: Using C# is a piece of cake, but my application has been developed in C++ and I cannot convert it. Daniele

    D 1 Reply Last reply
    0
    • Q qrverona

      Dear all, I'm writing a C++ (.NET 2003 with MFC) application that needs to query several data through WMI. I have a problem while accessing to the "IPAddress" data managed by the Win32_NetworkAdapterConfiguration WMI class. It is stored as a string array, the first Get returns me this information, but I did not found any issue on how to get the array. bool CMyDoc::GetWMIItemValue( IWbemClassObject *pInstance, LPCWSTR pItemName, CStringArray& strArray) { VARIANT val; LONG lFlavour; HRESULT hGet; CIMTYPE cimType; VariantInit(&val); strArray.RemoveAll(); hGet = pInstance->Get( pItemName, 0, &val, // val cannot hold the result &cimType, // returns 2008 = string array &lFlavour); // returns 0 if (hGet == WBEM_S_NO_ERROR) { if (cimType == (CIM_STRING | CIM_FLAG_ARRAY)) { // val holds 0x2008 too, unusable // how can I access the array? } } Thank you for you help... PS: Using C# is a piece of cake, but my application has been developed in C++ and I cannot convert it. Daniele

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      qrverona wrote: I have a problem while accessing to the "IPAddress" data managed by the Win32_NetworkAdapterConfiguration WMI class. I would employ something like:

      HRESULT hr;
      _variant_t v;
      ULONG ulReturned;
      DWORD dwAuthLevel;
      IWbemLocator *pLocator;
      IWbemServices *pService = NULL;
      IEnumWbemClassObject *pEnum = NULL;
      IWbemClassObject *pClass;

      hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLocator);
      if (S_OK == hr)
      {
      hr = pLocator->ConnectServer(_bstr_t(L"root\\cimv2"), NULL, NULL, NULL, NULL, 0, NULL, &pService);
      if (WBEM_S_NO_ERROR == hr)
      {
      hr = CoQueryProxyBlanket(pService, NULL, NULL, NULL, &dwAuthLevel, NULL, NULL, NULL);
      hr = CoSetProxyBlanket(pService,
      RPC_C_AUTHN_DEFAULT,
      RPC_C_AUTHZ_NONE,
      NULL,
      dwAuthLevel,
      RPC_C_IMP_LEVEL_IMPERSONATE,
      NULL,
      EOAC_NONE);

          hr = pService->CreateInstanceEnum(\_bstr\_t("Win32\_NetworkAdapterConfiguration"), 
                                            WBEM\_FLAG\_RETURN\_IMMEDIATELY | WBEM\_FLAG\_FORWARD\_ONLY, 
                                            NULL, 
                                            &pEnum);
          if (WBEM\_S\_NO\_ERROR == hr)
          {
              do
              {
                  hr = pEnum->Next(WBEM\_INFINITE, 1, &pClass, &ulReturned);
                  if (WBEM\_S\_NO\_ERROR == hr)
                  {
                      hr = pClass->Get(L"IPAddress", 0, &v, NULL, NULL);
                      if (v.vt != VT\_NULL)
                          ...
      
                      pClass->Release();
                  }
              } while (WBEM\_S\_NO\_ERROR == hr);
          }
      }
      

      }


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups