2:备份并清空应用程序日志,复制代码另存为AppEvtLog_Clear_bak_C.vbs
- On Error Resume Next
- strYear = Year(Date)
- strMonth = Month(Date)
- If strMonth < 10 Then strMonth = 0 & strMonth
- strDay = Day(Date)
- If strDay < 10 Then strDay = 0 & strDay
- strDate = strYear & strMonth & strDay '得到当前日期
- strLogfileName = strYear & strMonth & strDay
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- strPath = "c:\" '日志保存位置
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Backup)}!\\" & strComputer & "\root\cimv2")
- Set colLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile where LogFileName='System'")
- For Each objLogfile in colLogFiles
- objLogFile.BackupEventLog(strPath & "System(" & strLogfileName & ").evt")
- objLogFile.ClearEventLog()
- Next
3:备份并清空安全日志,复制代码另存为SecEvtLog_Clear_bak_C.vbs
- On Error Resume Next
- strYear = Year(Date)
- strMonth = Month(Date)
- If strMonth < 10 Then strMonth = 0 & strMonth
- strDay = Day(Date)
- If strDay < 10 Then strDay = 0 & strDay
- strDate = strYear & strMonth & strDay '得到当前日期
- strLogfileName = strYear & strMonth & strDay
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- strPath = "c:\" '日志保存位置
- 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 colLogFiles
- objLogFile.BackupEventLog(strPath & "Application(" & strLogfileName & ").evt")
- objLogFile.ClearEventLog()
- Next
将上面的脚本设置计划任务,每月最后一天运行即可(自行定义备份频率)。 其中代码objLogFile.ClearEventLog()为清空日志,如果只需要备份而不清空日志的话删除此行即可。
- On Error Resume Next
- strYear = Year(Date)
- strMonth = Month(Date)
- If strMonth < 10 Then strMonth = 0 & strMonth
- strDay = Day(Date)
- If strDay < 10 Then strDay = 0 & strDay
- strDate = strYear & strMonth & strDay '得到当前日期
- strLogfileName = strYear & strMonth & strDay
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- strPath = "c:\" '日志保存位置
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Backup, Security)}!\\" & strComputer & "\root\cimv2")
- Set colLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile where LogFileName='Security'")
- For Each objLogfile in colLogFiles
- objLogFile.BackupEventLog(strPath & "Security(" & strLogfileName & ").evt")
- objLogFile.ClearEventLog()
- Next
本文出自 “Leaves驿站” 博客,请务必保留此出处http://yangye.blog.51cto.com/922715/265076