Logs event to Windows Application Event Log via ReportEvent function of advapi32 API. Refactored ve
Logs event to Windows Application Event Log via ReportEvent function of advapi32 API. Refactored version of code originally submitted by
API Declarations
"RegisterEventSourceA" (ByVal lpUNCServerName As String, ByVal lpSourceName As String) As Long
Private Declare Function DeregisterEventSource Lib "advapi32" _
(ByVal hEventLog As Long) As Boolean
Private Declare Function ReportEvent _
Lib "advapi32" Alias "ReportEventA" _
(ByVal hEventLog As Long, _
ByVal wType As Long, _
ByVal wCategory As Long, _
ByVal dwEventID As Long, _
ByVal lpUserSid As Long, _
ByVal wNumStrings As Long, _
ByVal dwDataSize As Long, _
lpStrings As Any, _
lpRawData As Any) As Long
Public Enum LogTypes
EVENTLOG_SUCCESS = &H0 'Success event
EVENTLOG_ERROR_TYPE = &H1 'Error event
EVENTLOG_WARNING_TYPE = &H2 'Warning event
EVENTLOG_INFORMATION_TYPE = &H4 'Information event
EVENTLOG_AUDIT_SUCCESS = &H8 'Success audit event
EVENTLOG_AUDIT_FAILURE = &H10 'Failure audit event
End Enum
Rate Logs event to Windows Application Event Log via ReportEvent function of advapi32 API. Refactored ve
(2(2 Vote))
, EventType As LogTypes _
, strEventMsg As String _
, Optional iEventID As Integer = 1 _
, Optional iCategory As Integer = 0) As Long
'******************************************************************
'Returns nonzero for success otherwize zero for fail
'Usage:
'LogEvent([Applicaiton Name], [EventLog Type], [Msg to be logged], [Optional Event ID], [Optional Category Number])
'
'Dim ret As Long
'ret = LogEvent(App.Title, EVENTLOG_SUCCESS, "Success event!!!!")
'******************************************************************
Dim hEvt As Long
Dim ret1 As Long
hEvt = RegisterEventSource(vbNullChar, strSource)
If (hEvt <> 0) Then
ret1 = ReportEvent(hEvt, EventType, iCategory, iEventID, 0, 1, 0, strEventMsg, vbNullChar)
If (ret1 = 0) Then
LogEvent = 0
Exit Function
End If
End If
LogEvent = DeregisterEventSource(hEvt)
End Function
Logs event to Windows Application Event Log via ReportEvent function of advapi32 API. Refactored ve Comments
No comments yet — be the first to post one!
Post a Comment