![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Copy Application Event Logs For Past 30 Days To XLS The script below works great; however, I'm having trouble getting the 30 day portion of the script working. Any help would be greatly appreciated. Thanks in advance for your help... On Error Resume Next strComputer = "." strFile = "C:\Application Event Logs.xls" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate,(Security)}!\\" & _ strComputer & "\root\cimv2") Set colLoggedEvents = objWMIService.ExecQuery _ ("Select * From Win32_NTLogEvent Where Logfile = 'Application'") 'EventType Value = Meaning ' 1 = Error ' 2 = Warning ' 3 = Information ' 4 = Security Success ' 5 = Security Failure ' 8 = Security audit success ' 16 = Security audit failure Set objExcel = CreateObject("Excel.Application") objExcel.Visible = False objExcel.Workbooks.Add objExcel.Cells(1,1).Value = "System Event log Errors+Warnings for " & strComputer objExcel.Cells(1,1).Font.Bold = True objExcel.Cells(1,1).Font.Size = 13 objExcel.Cells(1,1).Interior.ColorIndex = 11 objExcel.Cells(1,1).Interior.Pattern = 1 'xlSolid objExcel.Cells(1,1).Font.ColorIndex = 2 objExcel.Cells(1,1).Borders.LineStyle = 1 '= xlSolid objExcel.Cells(1,1).WrapText = True objExcel.Cells(2,1).Value = "Time: " & Now objExcel.Cells(2,1).Font.Bold = True objExcel.Cells(2,1).Font.Size = 12 objExcel.Cells(2,1).Interior.ColorIndex = 11 objExcel.Cells(2,1).Interior.Pattern = 1 'xlSolid objExcel.Cells(2,1).Font.ColorIndex = 2 objExcel.Cells(2,1).Borders.LineStyle = 1 '= xlSolid objExcel.Cells(2,1).WrapText = True objExcel.Cells(4,1).Value = "Time Generated" objExcel.Cells(4,1).Font.Bold = True objExcel.Cells(4,1).Font.Size = 11 objExcel.Cells(4,2).Value = "LogFile" objExcel.Cells(4,2).Font.Bold = True objExcel.Cells(4,2).Font.Size = 11 objExcel.Cells(4,3).Value = "Type" objExcel.Cells(4,3).Font.Bold = True objExcel.Cells(4,3).Font.Size = 11 objExcel.Cells(4,4).Value = "Event Code" objExcel.Cells(4,4).Font.Bold = True objExcel.Cells(4,4).Font.Size = 11 objExcel.Cells(4,5).Value = "Message" objExcel.Cells(4,5).Font.Bold = True objExcel.Cells(4,5).Font.Size = 11 x = 5 y = 1 For Each objEvent in colLoggedEvents If objEvent.Type="error" or objEvent.Type="warning" Then strTimeGen = (evtdatetime(objEvent.TimeGenerated)) strLogfile = objEvent.Logfile strType = objEvent.Type strEventCode = objEvent.EventCode srtMessage = Trim( Replace( objEvent.Message, vbCrLf, " ")) y1 = y objExcel.Cells(x,y1).Value = strTimeGen y1 = y1 + 1 objExcel.Cells(x,y1).Value = strLogfile y1 = y1 + 1 objExcel.Cells(x,y1).Value = strType y1 = y1 + 1 objExcel.Cells(x,y1).Value = strEventCode y1 = y1 + 1 objExcel.Cells(x,y1).Value = srtMessage x = x + 1 End If Next objExcel.Columns("A:E").Select objExcel.Selection.HorizontalAlignment = 1 'xlLeft objExcel.Selection.Borders.LineStyle = 1 '= xlSolid objExcel.Range("A1","E1").MergeCells = 1 objExcel.Range("A2","E2").MergeCells = 1 objExcel.Columns("A:AH").EntireColumn.AutoFit objExcel.DisplayAlerts = False Set objWorkbook = objExcel.ActiveWorkbook objWorkbook.SaveAs strFile objWorkbook.Close objExcel.Quit msgbox "Application Export Complete!" Function evtdatetime(evttime) Dim tmGen, dtPart,tmPart tmGen = Left(evttime,14) dtPart = Left(tmGen,8) tmPart = Right(tmGen,6) evtdatetime = Left(dtPart,4) & "/" & Mid(dtPart,5,2) & "/" & Right (dtPart,2) &","& _ Left(tmPart,2) & ":" & Mid(tmPart,3,2) & ":" & Right(tmPart,2) End Function |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: Only 8 More Days Till The Past Of All Computing, Just FYI. | Vista General | |||
| subject windows Vista Event Logs access through WMI ( Applications and Services Logs) | Vista networking & sharing | |||
| windows Vista Event Logs access through WMI ( Applications and Services Logs) | Vista General | |||
| Windows Mail Slowing down over past 2 days | Vista mail | |||
| Does anyone ever look past the first few days | Vista General | |||