Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delete Specific Event from EventViewer

Posted on 2010-11-22
5
Medium Priority
?
601 Views
Last Modified: 2012-08-14
Hi,
 
I need help on below script, I want to delete specific event from eventviewer but when I run below code then it gives me error
 
Error : (8, 1) (null): 0x80041017
 
Script:
 
strComputer = "WINXPPC1"
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate,(Security,Backup)}!\\" & _
strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Security' and EventCode='578'")
For Each objLogfile in colLogFiles
  objLogFile.ClearEventLog()
Next
 
I have used ClearEventLog with for loop when it gets events of 578 then it will start clearning those logs.
 
checked security events and there are 560 and 578 events but still getting error message.
 
Thanks in advance
 
Anurag
0
Comment
Question by:nicepenfriend
[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
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
Tompa99 earned 750 total points
ID: 34187281
Hello,

The reason for your error is that your WMi query is wrong.
SELECT * FROM Win32_NTEventLogFile WHERE LogFileName='Security' and EventCode='578'"

The part and EventCode='578' is not avalible in  Win32_NTEventLogFile

The Evencode is part of Win32_NTLogEvent since it's a single event.
And as far as I know you can't delete a single event in a eventlog.

Some info about the 2 Win32 Classes
http://msdn.microsoft.com/en-us/library/aa394226%28v=VS.85%29.aspx
and
http://msdn.microsoft.com/en-us/library/aa394225%28v=VS.85%29.aspx

Regards Tompa
0
 

Author Comment

by:nicepenfriend
ID: 34187308
Thanks for your reply could you please help me to modify this code which can delete specific event from eventviewer
0
 
LVL 5

Expert Comment

by:Tompa99
ID: 34187523
Hi

As far as I know it's not possible to delete a single event from one eventlog. You can only clear the complete log.

Best Regards Tompa
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 34192719
I backup that statement - you can't do that.
0
 

Author Closing Comment

by:nicepenfriend
ID: 34470134
This question solved most of my problem which i was facing
0

Featured Post

Independent Software Vendors: 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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

719 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