Solved

Delete Specific Event from EventViewer

Posted on 2010-11-22
5
590 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

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

Suggested Solutions

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 …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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