Полезный скрипт для чистки логов на серверных ОС. Можно добавить в Scheduled tasks. Сохраняем как "lol.vbs", автозапуск через cscript.exe lol.vbs.
Код:
If WScript.Arguments.Count > 1 Then
WScript.Quit
End If
Dim strComputer ' As String
If WScript.Arguments.Count > 0 Then
strComputer= WScript.Arguments(0)
Else
strComputer= "localhost"
End If
ClearEventLogs strComputer
Private Sub ClearEventLogs( _
strComputer)
Set objWMIService = GetObject( _
"winmgmts:" & "{impersonationLevel=impersonate,(Backup)}!\\" _
& strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery( _
"Select * from Win32_NTEventLogFile")
For Each objLogfile in colLogFiles
ClearEventLog strComputer, objLogfile.LogfileName
Next
End Sub
Private Sub ClearEventLog( _
strComputer, _
strEventLogName)
Set objWMIService = GetObject( _
"winmgmts:" & "{impersonationLevel=impersonate,(Backup)}!\\" _
& strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery( _
"Select * from Win32_NTEventLogFile where LogFileName='" _
& strEventLogName & "'")
For Each objLogfile in colLogFiles
objLogFile.ClearEventLog()
Next
End Sub
Private Function GetFormattedTimestamp()
Dim timestamp
timestamp = Now
GetFormattedTimestamp = Year(timestamp) _
& LPad(Month(timestamp), 2, "0") _
& LPad(Day(timestamp), 2, "0") _
& "_" & Replace(FormatDateTime(timestamp, 4), ":", "")
End Function
Private Function LPad( _
strValue, _
nLength, _
strPadCharacter)
Dim strPaddedValue
strPaddedValue = strValue
While (Len(strPaddedValue) < nLength)
strPaddedValue = strPadCharacter & strPaddedValue
WEnd
LPad = strPaddedValue
End Function