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.
uint32 ClearEventLog(
[in] string ArchiveFileName
);
-
ArchiveFileName [in]
-
Path and file name of the file to be cleared.
Observação
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 code | Description |
---|---|
|
Success |
|
Privilege Missing |
|
Invalid Parameter |
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.
Observação
A backup file can be specified to the ClearEventLog method if a backup of the data is desired before clearing the log.
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.
Observação
A backup file can be specified to the ClearEventLog method if a backup of the data is desired before clearing the log.
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";
}
Minimum supported client |
Windows XP |
Minimum supported server |
Windows Server 2003 |
Namespace |
Root\CIMV2 |
Header |
|
MOF |
|
DLL |
|