WMI getting IP-Address [modified]
-
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
-
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
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.
-
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.
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 ;)
-
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 ;)
-
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
Hi, it is a bit more complex than you seem to expect. You need
Win32_NetworkAdapterConfiguration
. It will return several rows, some haveIPEnabled
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 throughIPAddress
. 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.
-
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
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!