How get Win32_OperatingSystem.LastBootUpTime in da

2019-03-01 11:30发布

I have been trying to get LastBootUpTime using Win32_OperatingSystem class (WMI).

HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
        &pclsObj, &uReturn);

    if(0 == uReturn)
    {
        break;
    }

    VARIANT vtProp;

    // Get the value of the Name property
    hr = pclsObj->Get(L"LastBootUpTime", 0, &vtProp, 0, 0);          
    VariantClear(&vtProp);

I want to write this time to CTime or COleDateTime variable. But variable vtProp has BSTR type and look like 20100302185848.499768+300 Also any datetime property of any WMI class have BSTR type

How can I put datetime property of WMI class to CTime?


But how use SWbemDateTime.GetVarDate() in C++? In MSDN just scripting sample for this function

标签: c++ wmi
2条回答
ゆ 、 Hurt°
2楼-- · 2019-03-01 11:36

You'll have to do some parsing to convert it. The format is yyyyMMddhhmmss.ffffff+zzz (zzz is UTC offset in minutes). The SWbemDateTime.GetVarDate() method can do it for you.

查看更多
走好不送
3楼-- · 2019-03-01 11:41

You can safely ignore anything after the decimal point as in the format yyyymmddhhmmss..

查看更多
登录 后发表回答