Microsoft KB Archive/216089

= How To Back Up the NT Event Log in Visual Basic =

Article ID: 216089

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q216089



SUMMARY
Event logging in Windows provides a standard, centralized way for Windows and applications to record important software and hardware events. It also supplies a standard user interface for viewing the logs and a programming interface for examining the logs.

This article illustrates how to back up the NT Event Log with Visual Basic versions 4.0 and later. This can be done using the BackupEventLog API call. While Visual Basic versions 5.0 and later have built-in functionality for event-logging, they do not provide the backup functionality that the Win32 API does.



MORE INFORMATION
The following example shows how to back up the local Application Event Log to a file named appback.evt:

Step by Step Example
 Create a new standard project in Visual Basic. Form1 is created by default. Add a CommandButton to Form1 and change its name to cmdBackupEventLog .  Add the following code to the Form1 code window: Private Declare Function BackupEventLog Lib "advapi32.dll" Alias "BackupEventLogA" ( _   ByVal hEventLog As Long, _    ByVal lpBackupFileName As String) _ As Long

Private Declare Function CloseEventLog Lib "advapi32.dll" ( _   ByVal hEventLog As Long) _ As Long

Private Declare Function OpenEventLog Lib "advapi32.dll" Alias "OpenEventLogA" ( _   ByVal lpUNCServerName As String, _    ByVal lpSourceName As String) _ As Long

Private Sub cmdBackupEventLog_Click Dim hEventLog As Long Dim lretv As Long hEventLog = OpenEventLog(VBNullString, "Application") If hEventLog = 0 Then Debug.Print "OpenEventLog Failed" Exit Sub End If   lretv = BackupEventLog(hEventLog, "appback.evt") If lretv = 0 Then Debug.Print "BackupEventLog Failed" Exit Sub End If   lretv = CloseEventLog(hEventLog) If lretv = 0 Then Debug.Print "CloseEventLog Failed" Exit Sub End If

End Sub  Press the F5 key to run the project and click cmdBackupEventLog. This backs up the Event Log to the file appback.evt.

