QAxObject *getWmiInterObj(const QString &name){ if (name.isEmpty()) { qDebug("Interface name is empty"); return 0; } QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator"); if (!objIWbemLocator) { qDebug("WbemScripting.SWbemLocator not created"); return 0; } QAxObject *objWMIService = objIWbemLocator->querySubObject( "ConnectServer(QString&,QString&)", QString("."), QString("root\\cimv2")); if (!objWMIService) { qDebug("WMIService not created"); delete objIWbemLocator; return 0; } QString query = QString("SELECT * FROM Win32_NetworkAdapterConfiguration " "WHERE SettingID = \"%1\"").arg(name); QAxObject *objInterList = objWMIService->querySubObject( "ExecQuery(QString&))", query); if (!objInterList) { qDebug("Answer from ExecQuery is null"); delete objIWbemLocator; return 0; } if (objInterList->dynamicCall("Count").toInt() == 0) { qDebug("Count is 0"); delete objIWbemLocator; return 0; }// И теперь самое интересное QAxObject *enum1 = objInterList->querySubObject("_NewEnum"); if (!enum1) { qDebug("Query _NewEnum failed"); delete objIWbemLocator; return 0; } IEnumVARIANT* enumInterface = 0; enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface); if (!enumInterface) { qDebug("Query interface failed"); delete objIWbemLocator; return 0; } enumInterface->Reset(); QAxObject *item = 0; for (int i = 0; i < objInterList->dynamicCall("Count").toInt(); i++) { VARIANT *theItem = (VARIANT*)malloc(sizeof(VARIANT)); if (enumInterface->Next(1,theItem,NULL) == S_FALSE) { qDebug("enum next failed"); delete theItem; delete objIWbemLocator; return 0; } item = new QAxObject((IUnknown*)theItem->punkVal); if (!item) { qDebug("getting result item failed"); delete theItem; delete objIWbemLocator; return 0; } delete theItem; } delete objIWbemLocator; return item;}
QString query = QString("SELECT * FROM Win32_NetworkAdapterConfiguration " "WHERE SettingID = \"%1\"").arg(name);
objWMIService = objIWbemLocator->querySubObject("ConnectServer(QString&,QString&)",QString("."),QString("root\\cimv2"));
[\\ComputerName\NameSpace][:ClassName][.KeyProperty1=Value1][,KeyProperty2=Value2]…]где ComputerName – имя компьютера NameSpace – название пространства имен ClassName – имя класса KeyProperty1=Value1, KeyProperty2=Value2 – свойства объекта и значения, по которому он идентифицируется.