tags:

views:

315

answers:

3

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?

+1  A: 

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

tommieb75
+1  A: 

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.

Hans Passant
A: 

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

chekalin-v