Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Event Viewer One Click Clear

15 Nov 2012   #60
vsrawat

Windows 7 Ultimate x86/x64 dual boot
 
 

Have used the useful script many times.

There are 5 types of Events - Critical/ Error/ Warning/ Information/ Audit Success

Any method that we can retain, say, Critical and, maybe, Error, that are crucial for diagnosing problems in future, and can delete rest of the types that are informative?

How can we just stop Audit success type of events from getting recorded in event logs?

Thanks.
--


My System SpecsSystem Spec
12 Dec 2012   #61
Mirfster

Windows 7 Professional x64
 
 
VBS Version

First of all, thanks for the great batch files. Just wanted to add a VBS version that I created to do the same in case anyone was interested in it.

Please note, this does not have any checking for Admin rights, but that is since I usually have these running via a Software Delivery System (MDT, SCCM, etc) or are part of my MDT Applications.


Code:
On Error Resume Next

'Define and configure objects
Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec("%ComSpec% /C WEvtUtil.exe EL")
WshShellExecOutPut = WshShellExec.StdOut.ReadAll

'Read each line and clear the event logs 
For Each EventLog in Split (WshShellExecOutPut, VBNewLine)
    WScript.Echo "Clearing: " & EventLog
    WshShell.Run "WEvtUtil.exe CL " & EventLog, 0, TRUE
Next
My System SpecsSystem Spec
12 Dec 2012   #62
Brink
Microsoft MVP

64-bit Windows 10 build 10074
 
 

Hello Mirfster, and welcome to Seven Forums.

No problem. Here's your .vbs with a UAC prompt for elevation added to it.

Code:
'UAC prompt for elevation
If WScript.Arguments.Count = 0 Then
     Set objShell = CreateObject("Shell.Application")
     objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " Run", , "runas", 1
Else
 
On Error Resume Next
 
'Define and configure objects
Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec("%ComSpec% /C WEvtUtil.exe EL")
WshShellExecOutPut = WshShellExec.StdOut.ReadAll
 
'Read each line and clear the event logs 
For Each EventLog in Split (WshShellExecOutPut, VBNewLine)
    WScript.Echo "Clearing: " & EventLog
    WshShell.Run "WEvtUtil.exe CL " & EventLog, 0, TRUE
Next
 
End If
My System SpecsSystem Spec
12 Dec 2012   #63
Mirfster

Windows 7 Professional x64
 
 

Thanks Brink, that is a nice addition.
My System SpecsSystem Spec
.


12 Dec 2012   #64
Brink
Microsoft MVP

64-bit Windows 10 build 10074
 
 

You're welcome.

I'd recommend to remove the line below to not have to click on OK for each log cleared. Only a few million of them.

Code:
WScript.Echo "Clearing: " & EventLog

Maybe this instead:

Code:
'UAC prompt for elevation
If WScript.Arguments.Count = 0 Then
     Set objShell = CreateObject("Shell.Application")
     objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " Run", , "runas", 1
Else
 
On Error Resume Next

'Define and configure objects
Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec("%ComSpec% /C WEvtUtil.exe EL")
WshShellExecOutPut = WshShellExec.StdOut.ReadAll

'Read each line and clear the event logs 
For Each EventLog in Split (WshShellExecOutPut, VBNewLine)
        WshShell.Run "WEvtUtil.exe CL " & EventLog, 0, TRUE
Next
 
End If
 
MsgBox "Event Viewer logs have been successfully cleared."
My System SpecsSystem Spec
12 Dec 2012   #65
Mirfster

Windows 7 Professional x64
 
 

Actually, I just left that in there so that when it is being ran via "CScript.exe" it shows progress. The code I provided is actually a snippet from my VBS that I use to prepare my base image.

I see what you mean though if it were to be launched via "WScript.exe".
My System SpecsSystem Spec
28 May 2013   #66
Rockit

Windows 7 Premium 64 Bit
 
 

Hi Everyone,

Has a final and best version been decided?

Thank You
My System SpecsSystem Spec
28 May 2013   #67
Brink
Microsoft MVP

64-bit Windows 10 build 10074
 
 

Hello Rockit,

Either option in the tutorial does the same thing. It's just a matter of which one you would like to use.
My System SpecsSystem Spec
09 Feb 2014   #68
Captain Zero

Windows 7 Home Premium x64
 
 

Just the thing I was looking for, thanks!
My System SpecsSystem Spec
15 Mar 2014   #69
m4paws

Windows 7 Ultimate x64
 
 

Great tool, thanks very much. I've become a bit OCD about no errors on boot up, so this really comes in handy
My System SpecsSystem Spec
Comment

 Event Viewer One Click Clear




Tutorial Tools





Similar help and support threads
Windows 7 Tutorial Category
Event Viewer Event Id 2002, Source: EapHost, Log Application
Well, I tryed to manage page-file but unfortunataly it resulted in problems. Then I lost VAIO-CARE and 7 ZIP files too. When I open Event Viewer every single day I see this: event Id 2002, Souce: Eap Host, Log name: Application and number of Eventes: 84. As I am desparate about that, What sould...
General Discussion
Event Viewer: Clear All Events
How to Clear all Event Logs in Event Viewer using Windows PowerShell This tutorial will show you how to quickly clear all event logs in Event Viewer with a one line PowerShell script. This one line command clears each log in the Event log list one at a time. wevtutil el gets the Event log...
Tutorials
BSOD when watching videos on youtube, Event 41 in Event Viewer
It's been a while since I've experienced a BSOD as I'm viewing a video on youtube. It would freeze as if the audio was caught in mid-stream then BSOD, then would restart automatically. I go to Event Viewer after windows as loaded and I see Event 41 Kernel-Power in there. I had this issue...
BSOD Help and Support
After BSOD Event Viewer Logs Event ID 3012 and 3011 every time I boot
I was running 3DMark06 and got a BSOD code 124. After that every time I boot Event Viewer logs Error Codes ID 3012 and 3011. Attached are screenshots of both. I googled this and found two different threads where someone suggested to rebuild the performance counters. Both responses were...
BSOD Help and Support
How To Clear Administrative Events Log - Event Viewer
Hi: Does anyone know how to clear the Administrative Events log listed under Custom Views in the Event Viewer? All the logs listed under the Windows logs have options to clear, but the above does not. Thanks, ColTom2
Performance & Maintenance
WHEA-Logger event 18/19 errors in Event Viewer (W7 Home Premium)
Hi, I was hoping somebody could offer an insight on the below, as searching around I've not found much to go on other than "overheating" Basically my laptop has been having very high temperatures for a long time (usually ~60C for CPU and often 100-110 for GPU...insanely high, in other words)...
Hardware & Devices

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 11:21.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App