VB Code:
Option Explicit
Private Declare Function GetVersion Lib "kernel32" () As Long
Private Const EVENTLOG_SEQUENTIAL_READ = &H1
Private Const EVENTLOG_SEEK_READ = &H2
Private Const EVENTLOG_FORWARDS_READ = &H4
Private Const EVENTLOG_BACKWARDS_READ = &H8
Public Enum EventType
EError = &H1
EWarning = &H2
EInformation = &H4
ESuccess = &H0
EAuditSuccess = &H8
EAuditFailure = &H10
End Enum
Private Declare Function OpenEventLog Lib "advapi32.dll" Alias "OpenEventLogA" (ByVal lpUNCServerName As String, ByVal lpSourceName As String) As Long
Private Declare Function ReportEvent Lib "advapi32.dll" Alias "ReportEventA" (ByVal hEventLog As Long, ByVal wType As EventType, ByVal wCategory As Long, ByVal dwEventID As Long, lpUserSid As Any, ByVal wNumStrings As Long, ByVal dwDataSize As Long, lpStrings As String, lpRawData As Any) As Long
Private Declare Function CloseEventLog Lib "advapi32.dll" (ByVal hEventLog As Long) As Long
Dim hEventLog As Long, Details As String
Private Sub cmdreport_Click()
If GetVersion() And &H80000000 Then
MsgBox "Event logging is not available in win 9X.", vbCritical, "Error(unavailable function)...!"
Else
Details = "Error"
hEventLog = OpenEventLog(vbNullString, Details)
ReportEvent hEventLog, EError, 0, 0, ByVal 0&, 1, 0, "Event Log test.", ByVal 0&
CloseEventLog hEventLog
End If
End Sub