Event Log
Event Log Manipulations:
1. Reading the Event Log
2. Clearing the Event Log
3. Creating backup of the Event Log
Code Snippet #1:
strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" _& strComputer & "\root\cimv2")Set colLoggedEvents = objWMIService.ExecQuery _("Select * from Win32_NTLogEvent " _& "Where Logfile = 'System'")For Each objEvent in colLoggedEventsWscript.Echo "Category: " & objEvent.Category & VBNewLine _& "Computer Name: " & objEvent.ComputerName & VBNewLine _& "Event Code: " & objEvent.EventCode & VBNewLine _& "Message: " & objEvent.Message & VBNewLine _& "Record Number: " & objEvent.RecordNumber & VBNewLine _& "Source Name: " & objEvent.SourceName & VBNewLine _& "Time Written: " & objEvent.TimeWritten & VBNewLine _& "Event Type: " & objEvent.Type & VBNewLine _& "User: " & objEvent.UserNext
Code Snippet #2:
strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate,(Backup)}!\\" & _strComputer & "\root\cimv2")Set colLogFiles = objWMIService.ExecQuery _("Select * from Win32_NTEventLogFile " _& "Where LogFileName='Application'")For Each objLogfile in colLogFilesobjLogFile.ClearEventLog()WScript.Echo "Cleared application event log file"Next
Code Snippet #3:
strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate,(Backup)}!\\" & _strComputer & "\root\cimv2")Set colLogFiles = objWMIService.ExecQuery _("Select * from Win32_NTEventLogFile " _& "Where LogFileName='Application'")For Each objLogfile in colLogFileserrBackupLog = objLogFile.BackupEventLog( _"c:\scripts\application.evt")WScript.Echo "File saved as c:\scripts\applications.evt"Next
No comments:
Post a Comment