Solved

Delete Specific Event from EventViewer

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

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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