ClearEventLog Method

Clears the specified event log, and optionally saves the current copy of the logfile to a backup file. This function fails if the event log is empty or a file already exists with the same name as the backup file.


  obj.ClearEventLog(EventLogName string, OutputFolderName string, [MachineName string])
  where obj is an OpScrUtil.EventLog object 


EventLogName Specifies the name of the log file to backup such as Application, System etc.
OutputFolderName Specifies the folder to which the output file should be saved. When backing up event logs from the local computer, this parameter can be a string containing system environment variable (e.g. %TEMP%). On remote computers where the system environment may vary, set this parameter to a specific foldername or an empty string.
SavedFileName Specifies the name of the file to which the eventlog was saved. If this parameter is NULL, the eventlog file being cleared is not backed up.
MachineName Specifies the target computer. This parameter is optional. If not specified or an empty string, the local computer is the target.

Return Type



To clear the System eventlog file, enter:

 Set obj = CreateObject("OpScrUtil.EventLog")
 If obj.ClearEventLog("System", "%TEMP%",varOutFileName)then
   MsgBox "The eventlog is cleared. Backup of the log is saved as " & varoutFileName
   MsgBox obj.GetError()
 End If

This example shows how to clear an event log and optionally create a backup of the log.