Function Reference


_EventLog__Notify

Enables an application to receive event notifications

#include <EventLog.au3>
_EventLog__Notify ( $hEventLog, $hEvent )

Parameters

$hEventLog A handle to the event log
$hEvent A handle to a manual-reset event object

Return Value

Success: True
Failure: False

Remarks

This function does not work with remote handles.
If the $hEventLog parameter is the handle to an event log on a remote computer, this function returns zero, and GetLastError returns ERROR_INVALID_HANDLE.
When an event is written to the log specified by $hEventLog, the system uses the PulseEvent function to set the event specified by the $hEvent parameter to the signaled state.
If the thread is not waiting on the event when the system calls PulseEvent, the thread will not receive the notification.
Therefore, you should create a separate thread to wait for notifications.
Note that the system calls PulseEvent no more than once every five seconds.
Therefore, even if more than one event log change occurs within a five second interval, you will only receive one notification.
The system will continue to notify you of changes until you close the handle to the event log.
To close the event log, use the _EventLog__Close() or _EventLog__DeregisterSource().

Related

_EventLog__Close, _EventLog__DeregisterSource

Example

#include <EventLog.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIHObj.au3>
#include <WinAPIProc.au3>

Global $g_idMemo

Example()

Func Example()
        Local $hEventLog, $hEvent, $iResult

        ; Create GUI
        GUICreate("EventLog", 600, 300)
        $g_idMemo = GUICtrlCreateEdit("", 2, 2, 596, 294, 0)
        GUICtrlSetFont($g_idMemo, 9, $FW_NORMAL, $GUI_FONTNORMAL, "Courier New")
        GUISetState(@SW_SHOW)

        ; Set up event
        $hEventLog = _EventLog__Open("", "Security")
        $hEvent = _WinAPI_CreateEvent(0, False, False, "")
        _EventLog__Notify($hEventLog, $hEvent)

        ; Wait for new event to occur
        MemoWrite("Waiting for new event")
        $iResult = _WinAPI_WaitForSingleObject($hEvent)
        _WinAPI_CloseHandle($hEvent)
        _EventLog__Close($hEventLog)

        ; Write results
        If $iResult = -1 Then
                MemoWrite("Wait failed")
        Else
                MemoWrite("New event occurred")
        EndIf

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
        GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite