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. WMI getting IP-Address [modified]

WMI getting IP-Address [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestionannouncement
6 Posts 4 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.
  • M Offline
    M Offline
    Marcel Vogt
    wrote on last edited by
    #1

    Hi, i'm using WMI to get some Parameters of the local Computer. Here is a Sample Code Snippet:

        pEnumerator = NULL;
        hres = pSvc
    			->ExecQuery(
            bstr_t("WQL"), 
            bstr_t("SELECT * FROM Win32_BIOS"),
            WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
            NULL,
            &pEnumerator);
    
        *pclsObj;    
    		uReturn = 0;
       
        while (pEnumerator)
        {
            HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
                &pclsObj, &uReturn);
    
            if(0 == uReturn)
            {
                break;
            }
    
    	VARIANT vtprop;
    	hr = pclsObj->Get(L"SerialNumber", 0, &vtprop, 0, 0);
    	wcout << vtprop.bstrVal << endl;
    
            VariantClear(&vtprop);
    
            pclsObj->Release();
        }
    

    This works very well. How must i change this, to show the IP-Adressses of the Computer? Only with Changing to "Win32_NetworkAdapterConfiguration" and "IPAddress" instead of "SerialNumber" doesn't works. I think, because IPAdress is an Array in WMI?

    modified on Saturday, June 19, 2010 12:50 PM

    B L L 3 Replies Last reply
    0
    • M Marcel Vogt

      Hi, i'm using WMI to get some Parameters of the local Computer. Here is a Sample Code Snippet:

          pEnumerator = NULL;
          hres = pSvc
      			->ExecQuery(
              bstr_t("WQL"), 
              bstr_t("SELECT * FROM Win32_BIOS"),
              WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
              NULL,
              &pEnumerator);
      
          *pclsObj;    
      		uReturn = 0;
         
          while (pEnumerator)
          {
              HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
                  &pclsObj, &uReturn);
      
              if(0 == uReturn)
              {
                  break;
              }
      
      	VARIANT vtprop;
      	hr = pclsObj->Get(L"SerialNumber", 0, &vtprop, 0, 0);
      	wcout << vtprop.bstrVal << endl;
      
              VariantClear(&vtprop);
      
              pclsObj->Release();
          }
      

      This works very well. How must i change this, to show the IP-Adressses of the Computer? Only with Changing to "Win32_NetworkAdapterConfiguration" and "IPAddress" instead of "SerialNumber" doesn't works. I think, because IPAdress is an Array in WMI?

      modified on Saturday, June 19, 2010 12:50 PM

      B Offline
      B Offline
      Baltoro
      wrote on last edited by
      #2

      Go over to Microsoft and download: WMI CIM Studio. With it you can search the entire WMI on your local machine. But, and I'm trying to remember, I think the IP address is written to the Registry when you connect to a Wireless network. I'd have to look it up. Get back tp you.

      M 1 Reply Last reply
      0
      • B Baltoro

        Go over to Microsoft and download: WMI CIM Studio. With it you can search the entire WMI on your local machine. But, and I'm trying to remember, I think the IP address is written to the Registry when you connect to a Wireless network. I'd have to look it up. Get back tp you.

        M Offline
        M Offline
        Marcel Vogt
        wrote on last edited by
        #3

        Sorry but this is not the solution for my Problem. I need help with my C++-Code above. That's why i have asked in this forum and not anywhere else ;)

        B 1 Reply Last reply
        0
        • M Marcel Vogt

          Sorry but this is not the solution for my Problem. I need help with my C++-Code above. That's why i have asked in this forum and not anywhere else ;)

          B Offline
          B Offline
          Baltoro
          wrote on last edited by
          #4

          OK

          1 Reply Last reply
          0
          • M Marcel Vogt

            Hi, i'm using WMI to get some Parameters of the local Computer. Here is a Sample Code Snippet:

                pEnumerator = NULL;
                hres = pSvc
            			->ExecQuery(
                    bstr_t("WQL"), 
                    bstr_t("SELECT * FROM Win32_BIOS"),
                    WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
                    NULL,
                    &pEnumerator);
            
                *pclsObj;    
            		uReturn = 0;
               
                while (pEnumerator)
                {
                    HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
                        &pclsObj, &uReturn);
            
                    if(0 == uReturn)
                    {
                        break;
                    }
            
            	VARIANT vtprop;
            	hr = pclsObj->Get(L"SerialNumber", 0, &vtprop, 0, 0);
            	wcout << vtprop.bstrVal << endl;
            
                    VariantClear(&vtprop);
            
                    pclsObj->Release();
                }
            

            This works very well. How must i change this, to show the IP-Adressses of the Computer? Only with Changing to "Win32_NetworkAdapterConfiguration" and "IPAddress" instead of "SerialNumber" doesn't works. I think, because IPAdress is an Array in WMI?

            modified on Saturday, June 19, 2010 12:50 PM

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, it is a bit more complex than you seem to expect. You need Win32_NetworkAdapterConfiguration. It will return several rows, some have IPEnabled set to true; those should correspond to physical network adapters, which each can have one or more IP addresses; these are returned as a string array through IPAddress. A little Google action should turn up sample code in the language of your choice. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

            1 Reply Last reply
            0
            • M Marcel Vogt

              Hi, i'm using WMI to get some Parameters of the local Computer. Here is a Sample Code Snippet:

                  pEnumerator = NULL;
                  hres = pSvc
              			->ExecQuery(
                      bstr_t("WQL"), 
                      bstr_t("SELECT * FROM Win32_BIOS"),
                      WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
                      NULL,
                      &pEnumerator);
              
                  *pclsObj;    
              		uReturn = 0;
                 
                  while (pEnumerator)
                  {
                      HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
                          &pclsObj, &uReturn);
              
                      if(0 == uReturn)
                      {
                          break;
                      }
              
              	VARIANT vtprop;
              	hr = pclsObj->Get(L"SerialNumber", 0, &vtprop, 0, 0);
              	wcout << vtprop.bstrVal << endl;
              
                      VariantClear(&vtprop);
              
                      pclsObj->Release();
                  }
              

              This works very well. How must i change this, to show the IP-Adressses of the Computer? Only with Changing to "Win32_NetworkAdapterConfiguration" and "IPAddress" instead of "SerialNumber" doesn't works. I think, because IPAdress is an Array in WMI?

              modified on Saturday, June 19, 2010 12:50 PM

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Marcel Vogt wrote:

              How must i change this, to show the IP-Adressses of the Computer? Only with Changing to "Win32_NetworkAdapterConfiguration" and "IPAddress" instead of "SerialNumber" doesn't works.

              I believe that using WMI is the easier but not the best option to work with IP addresses.You have entire IP helper API right here http://msdn.microsoft.com/en-us/library/aa366071(VS.85).aspx[^] which contains set of functions for IP management.For example GetIpAddrTable function will help you to examine IP-v4 mapping table.

              Life is a stage and we are all actors!

              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