Solved

Delete Specific Event from EventViewer

Posted on 2010-11-22
5
551 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
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
Tompa99 earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
I backup that statement - you can't do that.
0
 

Author Closing Comment

by:nicepenfriend
Comment Utility
This question solved most of my problem which i was facing
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

14 Experts available now in Live!

Get 1:1 Help Now