Solved

Clearing Application log programmatically

Posted on 2008-10-28
5
468 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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