I have been trying to get LastBootUpTime using Win开发者_运维技巧32_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
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.
You can safely ignore anything after the decimal point as in the format yyyymmddhhmmss..
精彩评论