Return to Snippet

Revision: 58200
at July 1, 2012 03:42 by Rectifier

Initial Code
@echo off
::Tested on a local machine using Windows 7 x64 Home Premium
::Use the ping command to wait -n # seconds; change # for time to wait
::Basic code can be found in various places on the internet
::Modified by Rectifier 06-30-2012

::If you receive an error try running the batch file as an administrator
::Note that the event log has to be enabled to begin with or this is a fairly useless batch

::Make readable prompt
echo. & echo. & echo.
echo Clearing event logs...
::Clear event logs by searching for them using a for loop
@for /f %%i in ( 'wevtutil el' ) do wevtutil cl "%%i" >NUL 2>&1
::Clear event logs not found by the for loop
wevtutil.exe cl "Microsoft-Windows-Diagnosis-DPS/Operational"
wevtutil.exe cl "Microsoft-Windows-User Profile Service/Operational"
wevtutil.exe cl "Microsoft-Windows-Windows Defender/Operational"
wevtutil.exe cl "Microsoft-Windows-Windows Defender/WHC"
wevtutil.exe cl "Microsoft-Windows-Windows Firewall With Advanced Security/Firewall"
wevtutil.exe cl System
::Informing the batch is finished executing
echo. & echo.
echo Batch finished!
ping -n 3 | find "Reply" > nul

Initial URL

Initial Description
This is a simple batch script to clear the event logs from a windows 7 or server 2008 machine. The script does *not* save these logs. This was tested on a local machine but could be adapted for remote use.

Initial Title
Clear Windows 7 Event Log

Initial Tags
event, windows, log

Initial Language
DOS Batch