如何確定我所在的計算機是否有夏時制? (最好使用WMI)使用WMI在Vista/Win7上檢查夏令時
根據this article at TechNet,我可以查詢SELECT DaylightInEffect FROM Win32_ComputerSystem
,但在Vista或Win7上不支持屬性DaylightInEffect
。由於我的程序可以在各種系統(XP,Vista,7)上運行,因此我希望通過一些可移植的方式查找。
如何確定我所在的計算機是否有夏時制? (最好使用WMI)使用WMI在Vista/Win7上檢查夏令時
根據this article at TechNet,我可以查詢SELECT DaylightInEffect FROM Win32_ComputerSystem
,但在Vista或Win7上不支持屬性DaylightInEffect
。由於我的程序可以在各種系統(XP,Vista,7)上運行,因此我希望通過一些可移植的方式查找。
有記錄的支持的操作系統列表不準確,這在我嘗試Win7時效果很好。我想不出任何其他操作系統都不支持的原因,用Win32 API(GetTimeZoneInformation)很容易找到它。
您可以使用WmiCodeCreator進行快速檢查。
這是一個使用問題中引用的WMI查詢實現的布爾函數。
(相關: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
事實上,它似乎在實踐工作。耶爲無證API。 – Piskvor 2009-11-26 21:03:44