Solved

Clearing Application log programmatically

Posted on 2008-10-28
5
461 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
Comment Utility
0
 
LVL 8

Expert Comment

by:tony_angelopoulos
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

10 Experts available now in Live!

Get 1:1 Help Now