Use WMI to check local time zone

According to MSDN,

The Win32_TimeZone WMI class represents the time zone information for a computer system running Windows, which includes the changes required for transitioning to daylight saving time transition.

The following function will display all properties from this class, which reflect the local computer that the code is run on. See Win32_TimeZone Class for a full discussion of each property and what it represents.

There's only one time zone setting, but a For Each Loop is required because trying to access timeZones(0) or timeZones.Item(0) didn't work.

Function GetTimeZoneInfo()

Dim objWMI As Object
Dim timeZones As Object
Dim timeZone As Object

  Set objWMI = GetWMIService

  Set timeZones = objWMI.ExecQuery("Select * from Win32_TimeZone")

  For Each timeZone In timeZones
    Debug.Print timeZone.Bias
    Debug.Print timeZone.Caption
    Debug.Print timeZone.DaylightBias
    Debug.Print timeZone.DaylightDay
    Debug.Print timeZone.DaylightDayOfWeek
    Debug.Print timeZone.DaylightHour
    Debug.Print timeZone.DaylightMillisecond
    Debug.Print timeZone.DaylightMinute
    Debug.Print timeZone.DaylightMonth
    Debug.Print timeZone.DaylightName
    Debug.Print timeZone.DaylightSecond
    Debug.Print timeZone.DaylightYear
    Debug.Print timeZone.Description
    Debug.Print timeZone.SettingID
    Debug.Print timeZone.StandardBias
    Debug.Print timeZone.StandardDay
    Debug.Print timeZone.StandardDayOfWeek
    Debug.Print timeZone.StandardHour
    Debug.Print timeZone.StandardMillisecond
    Debug.Print timeZone.StandardMinute
    Debug.Print timeZone.StandardMonth
    Debug.Print timeZone.StandardName
    Debug.Print timeZone.StandardSecond
    Debug.Print timeZone.StandardYear
  Next timeZone

End Function

Function GetWMIService() As Object
Dim strComputer As String

  strComputer = "."

  Set GetWMIService = GetObject("winmgmts:" _
                              & "{impersonationLevel=impersonate}!\\" _
                              & strComputer & "\root\cimv2")
End Function

Site last updated: May 17, 2012

Random Data Generator