|
適当に・・・
testのほうを実行してください。
Public Sub test()
Call EnumShutdownDateTime(Range("A1"))
End Sub
Public Sub EnumShutdownDateTime(ByVal r As Range)
Dim strComputer As String
Dim objWMIService As Object
Dim colLoggedEvents As Object
Dim objEvent As Object
Dim offsetRow As Long
Dim tTimeWritten As Date
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'System' and " _
& "EventCode = '6006'")
If colLoggedEvents.Count > 0 Then
offsetRow = 0
Application.ScreenUpdating = False
For Each objEvent In colLoggedEvents
tTimeWritten = _
ConvUTCtoJSC(ParseTimeWritten(objEvent.TimeWritten))
r.Offset(offsetRow, 0).Value = tTimeWritten
offsetRow = offsetRow + 1
Next objEvent
Application.ScreenUpdating = True
End If
Set colLoggedEvents = Nothing
Set objWMIService = Nothing
End Sub
Private Function ParseTimeWritten(ByVal v As Variant) As Date
ParseTimeWritten = _
CDate(Mid(v, 1, 4) & "/" & Mid(v, 5, 2) & "/" & Mid(v, 7, 2) & _
" " & Mid(v, 9, 2) & ":" & Mid(v, 11, 2) & ":" & Mid(v, 13, 2))
End Function
Private Function ConvUTCtoJSC(ByVal d As Date) As Date
ConvUTCtoJSC = DateAdd("h", 9, d)
End Function
|
|