Solved

Clearing Application log programmatically

Posted on 2008-10-28
5
467 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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