Jump to content

Recommended Posts

Is there a way setup a system event listener, so it would execute a function when specific event id triggered?

Currently I'm using task scheduler, where I created a new task that executes autoit script when triggered event id:

image.png.7233b93c4182418a3415ffb02509582f.png

It works, but I was hoping I could do this directly in the script instead.

Any tips?

 

Thank you.

Link to post
Share on other sites

Maybe create a looping eventlog listener?

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

GUICreate("EventLog", 600, 300)
Global $g_idMemo = GUICtrlCreateEdit("See console output", 2, 2, 596, 294, 0)
GUICtrlSetFont($g_idMemo, 9, $FW_NORMAL, $GUI_FONTNORMAL, "Courier New")
GUISetState(@SW_SHOW)

; Read most current event record
$hEventLog = _EventLog__Open("", "Application")

Do

    $aEvent = _EventLog__Read($hEventLog, True, False) ; read last event
    ; $hEventLog = _EventLog__Open("", "System")
    ; $aEvent = _EventLog__Read($hEventLog)
    ; $aEvent = _EventLog__Read($hEventLog, True, False)
    MemoWrite("Result ............: " & $aEvent[0])
    MemoWrite("Record number .....: " & $aEvent[1])
    MemoWrite("Submitted .........: " & $aEvent[2] & " " & $aEvent[3])
    MemoWrite("Generated .........: " & $aEvent[4] & " " & $aEvent[5])
    MemoWrite("Event ID ..........: " & $aEvent[6])
    MemoWrite("Type ..............: " & $aEvent[8])
    MemoWrite("Category ..........: " & $aEvent[9])
    MemoWrite("Source ............: " & $aEvent[10])
    MemoWrite("Computer ..........: " & $aEvent[11])
    MemoWrite("Username ..........: " & $aEvent[12])
    MemoWrite("Description .......: " & $aEvent[13])
    MemoWrite("=====================================")

Until GUIGetMsg() = $GUI_EVENT_CLOSE

_EventLog__Close($hEventLog)

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

 

 

Edited by KaFu
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...