Clears the specified event log, and optionally saves the current copy of the log to a backup file.
Syntax
|
BOOL ClearEventLog(
__in HANDLE hEventLog,
__in LPCTSTR lpBackupFileName
);
|
Parameters
- hEventLog [in]
-
A handle to the event log to be cleared. This handle is returned by the
OpenEventLog function.
- lpBackupFileName [in]
-
The name of the backup file. If this file already exists, the function fails.
If the lpBackupFileName parameter is NULL, the current event log is not backed up.
Return Value
If the function succeeds, the return value is nonzero. The specified event log has been backed up (if lpBackupFileName is not NULL) and then cleared.
If the function fails, the return value is zero. To get extended error information, call
GetLastError. The
ClearEventLog function fails if the event log is empty or a file already exists with the same name as lpBackupFileName.
Remarks
After this function returns, any handles that reference the cleared event log cannot be used to read the log.
Examples
The following example demonstrates the use of the ClearEventLog function.
|
#include <windows.h>
#include <stdio.h>
BOOL MyClearLog(
LPTSTR pszSrcName ) // event source name
{
HANDLE hEventLog;
BOOL bSuccess;
hEventLog = OpenEventLog(NULL, pszSrcName);
if (NULL == hEventLog)
{
printf("Open event log failed.\n");
return FALSE;
}
bSuccess = ClearEventLog(hEventLog, NULL);
CloseEventLog(hEventLog);
return bSuccess;
} |
Requirements
| Client | Requires Windows Vista, Windows XP, or Windows 2000 Professional. |
| Server | Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server. |
|---|
| Header | Declared in Winbase.h; include Windows.h. |
| Library | Use Advapi32.lib. |
| DLL | Requires Advapi32.dll. |
| Unicode/ANSI | Implemented as ClearEventLogW (Unicode) and ClearEventLogA (ANSI). |
See Also
Event Logging Functions
OpenEventLog
Send comments about this topic to Microsoft
Build date: 9/19/2008