vbscript WMI - 获取事件日志tra截止日期
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript WMI - 获取事件日志tra截止日期相关的知识,希望对你有一定的参考价值。
strComputer = "."
dtmStartDateTime = Date2WMIdate(DateAdd("h","-2",Now))
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLogEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent WHERE LogFile = 'System' AND (Type = 'Warning' OR Type = 'Error') AND TimeWritten >= '" & dtmStartDateTime & "'")
For Each objItem in colLogEvents
wscript.echo objItem.message
Next
Function Date2WMIdate(strDate)
arrDate = Split(strDate," ")
strDate = arrDate(0)
strTime = arrDate(1)
dtmYear = Year(strDate)
dtmMonth = Month(strDate)
dtmDay = Day(strDate)
dtmHour = Hour(strTime)
dtmMin = Minute(strTime)
dtmSec = Second(strTime)
dtmMonth = addZero(dtmMonth)
dtmDay = addZero(dtmDay)
dtmHour = addZero(dtmHour)
dtmMin = addZero(dtmMin)
dtmSec = addZero(dtmSec)
Date2WMIdate = dtmYear & dtmMonth & dtmDay & dtmHour & dtmMin & dtmSec & ".000000-000"
End Function
Function addZero(intPartofDateTime)
if Len(intPartofDateTime) = 1 Then: addZero = "0" & intPartofDateTime: Else: addZero = intPartofDateTime: End If
End Function
以上是关于vbscript WMI - 获取事件日志tra截止日期的主要内容,如果未能解决你的问题,请参考以下文章
WMI VBScript 与 C#
ManagementEventWatcher(WMI) 通知来自远程计算机的事件时出现异常
vbscript WMI:将WMI日期转换为标准日期和时间
SSIS常用的包—WMI数据读取任务和WMI事件监听任务
vbscript WMI:RemoteShutdown
vbscript 使用StdRegProv类通过VBScript调用WMI注册表,但未指定体系结构