|
-
Jul 10th, 2006, 10:14 PM
#1
Thread Starter
Addicted Member
Report events
In VB we can report events by the following method (Win NT and higher)
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
This is fine but there is something missing , first looks to this picture
It say that the descripitor for event ........... cannot be found............. .
what my code need to report events as other windows applications that give full detalis about the error ?
-
Jul 11th, 2006, 08:03 PM
#2
Re: Report events
first of all you did not declare the function properly. Try this
VB Code:
Private Declare Function ReportEvent Lib "advapi32.dll" Alias "ReportEventA" ( _
ByVal hEventLog As Long, _
ByVal wType As Integer, _
ByVal wCategory As Integer, _
ByVal dwEventID As Long, _
lpUserSid As Any, _
ByVal wNumStrings As Integer, _
ByVal dwDataSize As Long, _
ByVal lpStrings As String, _
lpRawData As Any _
) As Long
There may be other problems I haven't seen yet.
-
Jul 11th, 2006, 08:11 PM
#3
Re: Report events
I think you might have to use
RegisterEventSource
instead of
OpenEventLog
see example
http://msdn.microsoft.com/library/de...g_an_event.asp
-
Jul 11th, 2006, 08:45 PM
#4
Thread Starter
Addicted Member
Re: Report events
No useful info at this link , even with this project http://support.microsoft.com/?kbid=154576 at M$ MSDN do the same as my code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|