Solved

Clearing Application log programmatically

Posted on 2008-10-28
5
462 Views
Last Modified: 2013-11-07
I have trouble with Application Log in Event Viewr because it constantly gets filled up. What I want to do is to build a utility that would clear the application log whenever it gets filled. I don't want to re-invent the wheel so I was wondering if anyone have done something like this before and what is the best way to approach this problem.
0
Comment
Question by:YZlat
5 Comments
 
LVL 19

Expert Comment

by:elimesika
ID: 22822395
0
 
LVL 8

Expert Comment

by:tony_angelopoulos
ID: 22822414
you will want to run this vbs script as a scheduled task every so often.  Just copy the code into notepad and save with a .vbs extension.  Then from your task scheduler call it at specific intervals.
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.ClearEventLog()

Next

Open in new window

0
 
LVL 8

Expert Comment

by:tony_angelopoulos
ID: 22822453
more information on scripting event logs can be found here (like for logs that meet specific conditions, backing them up before deletion, etc.)

http://www.microsoft.com/technet/scriptcenter/guide/sas_log_pcna.mspx?mfr=true
0
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 250 total points
ID: 22822534
You can set the properties of Application event log to over write events "Over write events as needed (oldest events first)" this will cause the events to be overwritten when it reaches the specified size.
Goto event viewer > Properties of Application events > change the settings here
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22823141
create an instance to the log you want to clear and after that just execute the following statement
EventLog1.Clear();
http://msdn.microsoft.com/en-us/library/d3wah3h5(VS.80).aspx
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now