WMI奇怪的价值观

时间:2017-04-29 18:20:02

标签: c++ windows wmi ram

我想在RAM中检测到WMI制造商。我得到奇怪的符号而不是实际数据的问题。我也使用wmic命令检查了它。屏幕截图如下所列。

截图:

enter image description here

enter image description here

我尝试过不同的方法在输出前检查值,但问题仍然存在。

代码:

VARIANT ramManufacturer;
pclsObj->Get(L"Manufacturer", 0, &ramManufacturer, 0, 0);
QString userRAMManufacturer;
QStringList ramProperty;
QStringList ramData;

   if (SysStringLen(ramManufacturer.bstrVal) != 0) {
       userRAMManufacturer = QString::fromWCharArray(ramManufacturer.bstrVal);

        if (!userRAMManufacturer.isEmpty()) {
            ramProperty << QObject::tr("Manufacturer");
            ramData << userRAMManufacturer;
        }
    }

或者

if (CComBSTR(ramManufacturer.bstrVal).Length() != 0) {
    userRAMManufacturer = QString::fromWCharArray(ramManufacturer.bstrVal);

    if (!userRAMManufacturer.isEmpty()) {
        ramProperty << QObject::tr("Manufacturer");
        ramData << userRAMManufacturer;
    }
}

如何解决此问题?提前谢谢。

1 个答案:

答案 0 :(得分:0)

@selbie

谢谢。我已检查Get值,现在值正确。

<强>代码:

if (ramManufacturer.vt != VT_NULL && ramManufacturer.vt == VT_BSTR) {
    userRAMManufacturer = QString::fromWCharArray(ramManufacturer.bstrVal);
    ramProperty << QObject::tr("Manufacturer");
    ramData << userRAMManufacturer;
}