Victor Chekalin
Victor Chekalin

Reputation: 87

How get Win32_OperatingSystem.LastBootUpTime in datetime format

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

Upvotes: 1

Views: 4803

Answers (2)

Hans Passant
Hans Passant

Reputation: 941237

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.

Upvotes: 3

t0mm13b
t0mm13b

Reputation: 34592

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

Upvotes: 1

Related Questions