- WMI Fun !! -|WMI StepWMI SampleSearchWMI Fun !! GroupsAbout WMI Fun !!
Top Page >> WMI Step >> UTC(協定世界時)を取得する
UTC(協定世界時)を取得する
Topics

現在のUTC(協定世界時)を取得するサンプルです。Win32_UTCTimeクラスを使用します。


Sample Code

Private Sub Command1_Click()

Dim UtcSet As SWbemObjectSet
Dim Utc As SWbemObject
Dim Locator As SWbemLocator
Dim Service As SWbemServices
Dim MesStr As String

Set Locator = New WbemScripting.SWbemLocator
Set Service = Locator.ConnectServer

Set UtcSet = Service.ExecQuery("Select * From Win32_UTCTime")

For Each Utc In UtcSet

    MesStr = MesStr & vbCrLf & Utc.Hour & ":" & _
            Utc.Minute & ":" & Utc.Second & vbCrLf
            
Next

MsgBox "UTC(協定世界時)です。" & _
            vbCrLf & MesStr & vbCrLf & "ですよ。"

Set UtcSet = Nothing
Set Utc = Nothing
Set Locator = Nothing
Set Service = Nothing

End Sub

Comment

実行すると現在の時刻をUTCにて表示します。
今回は時刻だけですがもちろん日付と年数も取得可能です。


WMI を本で勉強したい方へ。 Windows PowerShellインアクション を読んでみては?
なかなか WMI のことが乗っている書籍は少ないですが…管理系業務に係る方には楽しめるかも?
パソコンで目が疲れたら、ブルーベリーアイ
『ブルーベリーアイ』1粒中ビルベリーエキス160mg【楽天シニア市場】
 ^ Copyright(C) 1997-2008 とお All rights reserved. <<