Results 1 to 5 of 5

Thread: event log

  1. #1

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179

    event log

    can you use an api to write information to the event log?
    Due to the energy crisis, the light at the end of the tunnel has been turned off.
    Sorry for any inconvenience this may cause

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I have some code that will allow you to read entries in the Event Log. You might be able to modify it so you can do a write.

    If you want this code, let me know.

  3. #3

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179

    Post

    the code would be great, thanks
    Due to the energy crisis, the light at the end of the tunnel has been turned off.
    Sorry for any inconvenience this may cause

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Here you go.

    Public Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
    "RegisterEventSourceA" (ByVal lpUNCServerName As String, _
    ByVal lpSourceName As String) As Long
    Public Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
    ByVal hEventLog As Long) As Long
    Public Declare Function ReportEvent Lib "advapi32.dll" Alias _
    "ReportEventA" (ByVal hEventLog As Long, ByVal wType As Integer, _
    ByVal wCategory As Integer, ByVal dwEventID As Long, _
    ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
    ByVal dwDataSize As Long, plpStrings As Long, _
    lpRawData As Any) As Boolean
    Public Declare Function GetLastError Lib "kernel32" () As Long
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
    hpvDest As Any, hpvSource As Any, _
    ByVal cbCopy As Long)
    Public Declare Function GlobalAlloc Lib "kernel32" ( _
    ByVal wFlags As Long, _
    ByVal dwBytes As Long) As Long
    Public Declare Function GlobalFree Lib "kernel32" ( _
    ByVal hMem As Long) As Long

    Public Const EVENTLOG_SUCCESS = 0
    Public Const EVENTLOG_ERROR_TYPE = 1
    Public Const EVENTLOG_WARNING_TYPE = 2
    Public Const EVENTLOG_INFORMATION_TYPE = 4
    Public Const EVENTLOG_AUDIT_SUCCESS = 8
    Public Const EVENTLOG_AUDIT_FAILURE = 10

    Public Sub LogNTEvent(sString As String, iLogType As Integer, _
    iEventID As Long)
    Dim bRC As Boolean
    Dim iNumStrings As Integer
    Dim hEventLog As Long
    Dim hMsgs As Long
    Dim cbStringSize As Long

    hEventLog = RegisterEventSource("", App.Title)
    cbStringSize = Len(sString) + 1
    hMsgs = GlobalAlloc(&H40, cbStringSize)
    CopyMemory ByVal hMsgs, ByVal sString, cbStringSize
    iNumStrings = 1
    If ReportEvent(hEventLog, _
    iLogType, 0, _
    iEventID, 0&, _
    iNumStrings, cbStringSize, _
    hMsgs, hMsgs) = 0 Then
    MsgBox GetLastError()
    End If
    Call GlobalFree(hMsgs)
    DeregisterEventSource (hEventLog)
    End Sub

    Sub Main()
    Call LogNTEvent("Information from " & App.EXEName, _
    EVENTLOG_INFORMATION_TYPE, 1001)
    Call LogNTEvent("Warning from " & App.EXEName, _
    EVENTLOG_WARNING_TYPE, 1002)
    Call LogNTEvent("Error from " & App.EXEName, _
    EVENTLOG_ERROR_TYPE, 1003)
    MsgBox "Done"
    End Sub

  5. #5
    jhilb
    Guest
    If you have info on how to read the event log, specifically the description and user id of an event, I would much appreciate it.

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