开发者

Check for daylight saving time with WMI on Vista/Win7

How do I find out if the computer I'm on 开发者_C百科has daylight saving time in effect? (preferably using WMI)

According to this article at TechNet, I could query SELECT DaylightInEffect FROM Win32_ComputerSystem, but the property DaylightInEffect is not supported on Vista or Win7. As my program will run on various systems (XP, Vista, 7), I would appreciate some portable way of finding out.


The documented supported OS list is not accurate, this works fine on Win7 when I try it. I can't think of any reason it wouldn't be supported on any other OS, it is easy to find out with the Win32 API (GetTimeZoneInformation).

You can use WmiCodeCreator for a quick check.


Here is a boolean function that is implemented using the WMI query referenced in the question.

(Related: How Can I Determine My Time Zone Offset Using VBScript?)

Function IsDaylightInEffect()
    Const sComputer = "."

    Dim oWmiService : Set oWmiService = _
        GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
                  & sComputer & "\root\cimv2")

    Set cItems = oWmiService.ExecQuery("SELECT * FROM Win32_ComputerSystem")

    For Each oItem In cItems
        IsDaylightInEffect = oItem.DaylightInEffect
        Exit For
    Next
End Function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜