Results 1 to 4 of 4

Thread: Report events

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Cool Report events

    In VB we can report events by the following method (Win NT and higher)

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetVersion Lib "kernel32" () As Long
    4.  
    5. Private Const EVENTLOG_SEQUENTIAL_READ = &H1
    6. Private Const EVENTLOG_SEEK_READ = &H2
    7. Private Const EVENTLOG_FORWARDS_READ = &H4
    8. Private Const EVENTLOG_BACKWARDS_READ = &H8
    9.  
    10. Public Enum EventType
    11.     EError = &H1
    12.     EWarning = &H2
    13.     EInformation = &H4
    14.     ESuccess = &H0
    15.     EAuditSuccess = &H8
    16.     EAuditFailure = &H10
    17. End Enum
    18.  
    19. Private Declare Function OpenEventLog Lib "advapi32.dll" Alias "OpenEventLogA" (ByVal lpUNCServerName As String, ByVal lpSourceName As String) As Long
    20.  
    21. 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
    22.  
    23. Private Declare Function CloseEventLog Lib "advapi32.dll" (ByVal hEventLog As Long) As Long
    24.  
    25.  
    26. Dim hEventLog As Long, Details As String
    27.  
    28. Private Sub cmdreport_Click()
    29. If GetVersion() And &H80000000 Then
    30.         MsgBox "Event logging is not available in win 9X.", vbCritical, "Error(unavailable function)...!"
    31.     Else
    32.         Details = "Error"
    33.         hEventLog = OpenEventLog(vbNullString, Details)
    34.         ReportEvent hEventLog, EError, 0, 0, ByVal 0&, 1, 0, "Event Log test.", ByVal 0&
    35.         CloseEventLog hEventLog
    36. End If
    37. 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 ?

  2. #2
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Report events

    first of all you did not declare the function properly. Try this
    VB Code:
    1. Private Declare Function ReportEvent Lib "advapi32.dll" Alias "ReportEventA" ( _
    2.     ByVal hEventLog As Long, _
    3.     ByVal wType As Integer, _
    4.     ByVal wCategory As Integer, _
    5.     ByVal dwEventID As Long, _
    6.     lpUserSid As Any, _
    7.     ByVal wNumStrings As Integer, _
    8.     ByVal dwDataSize As Long, _
    9.     ByVal lpStrings As String, _
    10.     lpRawData As Any _
    11. ) As Long
    There may be other problems I haven't seen yet.

  3. #3
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Cool 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
  •  



Click Here to Expand Forum to Full Width