WMI'm Going Speed Dating

Published January 29, 2011
Advertisement
There's tonnes of example on how to use SWbemDateTime to convert from FILETIME's or CDates in VBScript, yet I couldn't find any for C++. So here's how...

All WMI queries that give or take datetime values, do so in a certain format called CIM_DATETIME. For scripting guys, this is only a minor inconvenience. The following listing is the entire code to display the OS install date in various formats:


' Create a new datetime object.
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")

' Retrieve a WMI object that contains a datetime value.
for each os in GetObject( _
"winmgmts:").InstancesOf ("Win32_OperatingSystem")

' The InstallDate property is a CIM_DATETIME.
MsgBox os.InstallDate
dateTime.Value = os.InstallDate

' Display the year of installation.
MsgBox "This OS was installed in the year " & dateTime.Year

' Display the installation date using the VT_DATE format.
MsgBox "Full installation date (VT_DATE format) is " _
& dateTime.GetVarDate

' Display the installation date using the FILETIME format.
MsgBox "Full installation date (FILETIME format) is " _
& dateTime.GetFileTime
next
Set datetime = Nothing

For the native coders among us, the standard Win32 time functions neither produce nor consume this format meaning we have to perform some jiggery poker to get it to play nice.

Read the rest on Just Let It Flow
0 likes 1 comments

Comments

Gaiiden
there's no HTML allowed, so stick to the WYSIWYG editor or Rich Text editor with BBCode tags.
January 29, 2011 03:19 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement
Advertisement