Logfile nach Datum
30.08.2008 11:06:36
Tino
Hallo,
ich hoffe das ich dies nicht umsonst gemacht habe,
weil auf eine Rückmeldung ich immer noch von dir warte.
Hiermit müsste auch deine erste Frage beantwortet sein.
Hiermit kannst du die Logfiles zu einem bestimmten Datum auslesen.
Modul Modul2
''Logfile =****
'Application
'System
'Security
''EventType =**
'1 Error
'2 Warning()
'3 Information()
'4 Security audit success
'5 Security audit failure
Sub Versuch()
Dim objWMIService As Object, colLoggedEvents As Object
Dim dtmStartDate As Object, dtmEndDate As Object
Dim strMessage As String, strDatum As String
Dim lngRow As Long
Dim SDatum As Date
SDatum = Date 'welches Datum auslesen (heute)?
Set objWMIService = GetObject("winmgmts:" _
& "\\" & "." & "\root\cimv2")
Const CONVERT_TO_LOCAL_TIME = True
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
dtmStartDate.SetVarDate SDatum, CONVERT_TO_LOCAL_TIME
dtmEndDate.SetVarDate SDatum + 1, CONVERT_TO_LOCAL_TIME
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where TimeWritten >= '" _
& dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "' and Logfile = 'System' and EventType = '3'")
Application.ScreenUpdating = False
Range("A2", Cells(Rows.Count, "C")).ClearContents
lngRow = 1
For Each objEvent In colLoggedEvents
lngRow = lngRow + 1
'Infotext
If IsNull(objEvent.Message) = False Then
strMessage = objEvent.Message
Do While Right$(strMessage, 1) = Chr(10) Or Right$(strMessage, 1) = Chr(13)
strMessage = Trim$(Left$(strMessage, Len(strMessage) - 1))
Loop
Cells(lngRow, "A") = strMessage
End If
''Datum
strDatum = Trim$(objEvent.TimeWritten)
If strDatum > "" Then Cells(lngRow, "B") = _
CDate(Mid(strDatum, 7, 2) & "." & Mid(strDatum, 5, 2) & "." & Mid(strDatum, 1, 4) & " " & _
Mid(strDatum, 9, 2) & ":" & Mid(strDatum, 11, 2) & ":" & Mid(strDatum, 13, 2))
'User
Cells(lngRow, "C") = IIf(IsNull(objEvent.User), "", Trim(objEvent.User))
''andere Parameter****************************
' Debug.Print "Category: " & objEvent.Category
' Debug.Print "Computer Name: " & objEvent.ComputerName
' Debug.Print "Event Code: " & objEvent.EventCode
' Debug.Print "Record Number: " & objEvent.RecordNumber
' Debug.Print "Source Name: " & objEvent.SourceName
' Debug.Print "Event Type: " & objEvent.Type
'**********************************************
Next
Application.ScreenUpdating = True
End Sub
Gruß Tino
www.VBA-Excel.de