Export (0) Print
Expand All

ClearEventLog method of the Win32_NTEventlogFile class

The ClearEventLog method clears the specified event log.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.

Syntax


uint32 ClearEventLog(
  [in]  string ArchiveFileName
);

Parameters

ArchiveFileName [in]

Path and file name of the file to be cleared.

Note  If the ArchiveFileName comes from a source that you do not know or trust, then this value should be verified before using it in a call to ClearEventLog.

Return value

Return codeDescription
0

Success

8

Privilege Missing

21

Invalid Parameter

 

Examples

The following VBScript sample demonstrates how to clear the entries from the System event log file on the local machine from instances of Win32_NTEventlogFile .

Note  A backup file can be specified to the ClearEventlog method if a backup of the data is desired before clearing the log. This script only applies to NT-based systems, as Win9x does not support event logs.

Set LogFileSet = GetObject("winmgmts:{(Backup,Security)}").ExecQuery("select * from Win32_NTEventLogFile where LogfileName='System'")

for each Logfile in LogFileSet
	RetVal = LogFile.ClearEventlog()
	if RetVal = 0 then WScript.Echo "Log Cleared"
next

The following perl sample demonstrates how to clear the entries from the System event log file on the local machine from instances of Win32_NTEventlogFile .

Note  A backup file can be specified to the ClearEventlog method if a backup of the data is desired before clearing the log. This script only applies to NT-based systems, as Win9x does not support event logs.


use strict;
use Win32::OLE;

close(STDERR);

my ($LogFile, $LogFileSet);
eval {$LogFileSet = Win32::OLE->GetObject("winmgmts:{(Backup,Security)}")->
	ExecQuery("SELECT * FROM Win32_NTEventLogFile WHERE LogfileName='System'");};
if(!$@ && defined $LogFileSet)
{
	foreach $LogFile (in $LogFileSet)
	{
		my $RetVal = $LogFile->ClearEventlog();
		if ($RetVal == 0)
		{
			print "\nLog Cleared\n";
		}
		else
		{
			print Win32::OLE->LastError, "\n";
		}
	}
}
else
{
	print Win32::OLE->LastError, "\n";
}

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Namespace

\root\CIMV2

MOF

Ntevt.mof

DLL

Ntevt.dll

See also

Operating System Classes
Win32_NTEventlogFile
WMI Tasks: Event Logs

 

 

Community Additions

ADD
Show:
© 2014 Microsoft