Solved

Clearing Application log programmatically

Posted on 2008-10-28
5
465 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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:…
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 …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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