Windows Tutorials

How to clear all event logs with .bat file for CMD

In this tutorial you will be shown how to clear all event logs with a .bat for CMD. This Bat file will come handy to clear stuck events from the logs or if your event viewer is crashing cause by too much data.

Let’s get started. 

  1. Open notepad or notepad++.
  2. Copy the contents blow and paste them into notepad.
  3. Save the file as clearevens.bat
  4. Right click on the newly created clearevens.bat and run it as administrator. 
@echo off

FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
for /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%%G")
echo.
echo All Event Logs have been cleared!
goto theEnd

:do_clear
echo clearing %1
wevtutil.exe cl %1
goto :eof

:noAdmin
echo Current user permissions to execute this .BAT file are inadequate.
echo This .BAT file must be run with administrative privileges.
echo Exit now, right click on this .BAT file, and select "Run as administrator".  
pause >nul

:theEnd
Exit

If you have any questions about the configuration or run into any issues please feel free to contact me.

author avatar
Patrick Domingues

Leave a Comment

Stay Informed

Receive instant notifications when new content is released.