Solved

Delete Specific Event from EventViewer

Posted on 2010-11-22
5
597 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 250 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 70

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

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

617 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