Getting IP Address through WMI
-
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
-
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
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