Jump to content

Search and display eventlog entry


Go to solution Solved by JLogan3o13,

Recommended Posts

  • Moderators
  • Solution

Help file - begin with _EventLog__Open

Edit: Bored. Try something like this:

#include <EventLog.au3>

$hLog = _EventLog__Open("", "System")
$sCount = _EventLog__Count($hLog)

For $i = $sCount To 1 Step -1
    $aEvent = _EventLog__Read($hLog, True, False, $i)
    If StringInStr($aEvent[13], "PowerBroker for Windows detected ") Then
        MsgBox(0, "Record Number: " & $aEvent[1], "Submitted: " & $aEvent[2] & " " & $aEvent[3] & @CRLF & "Description: " & $aEvent[13])
    EndIf
Next
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

It is in the help file, but you begin by opening the log. You are then reading from the last (most recent) entry to the first (oldest). For each entry you read, if part of the description includes the text you're looking for, then do something with that entry.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Yes. Look at the example for _EventLog__Read in the help file. It shows you how to do it with a GUI.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Im trying to write all the events that are found with all the arrays mentioned but im not getting any output:

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

$sFilePath = "C:\test.log"

$hFileOpen = FileOpen($sFilePath)

$hLog = _EventLog__Open("", "System")

$sCount = _EventLog__Count($hLog)


For $i = $sCount To 1 Step -1

    $aEvent = _EventLog__Read($hLog, True, False, $i)

    If StringInStr($aEvent[13], "PowerBroker for Windows detected a UAC prompt") Then

        ;MsgBox(0, "Record Number: " & $aEvent[1], "Submitted: " & $aEvent[2] & " " & $aEvent[3] & @CRLF & "Description: " & $aEvent[13])
        FileWrite($hFileOpen, "Record Number: " & $aEvent[1], "Submitted: " & $aEvent[2] & " " & $aEvent[3] & @CRLF & "Description: " & $aEvent[13])

    EndIf

Next
Link to comment
Share on other sites

  • Moderators

A couple of things:

  • The default mode for FileOpen, since you don't specify it, is Read Only. Check the help file for the parameter you need to fix this.
  • You also had some syntactical errors in your FileWrite line, see below (extra comma, missing &)
FileWriteLine($hFileOpen, "Record Number: " & $aEvent[1] & "Submitted: " & $aEvent[2] & " " & $aEvent[3] & @CRLF & "Description: " & $aEvent[13])
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@JLogan,

Thank you

This is what i have so far and is working:

#include <EventLog.au3>

$sFilePath = "C:\temp\PB_UAC_Prompt.log"

$hFileOpen = FileOpen($sFilePath, 1)

$hLog = _EventLog__Open("", "System")

$sCount = _EventLog__Count($hLog)


For $i = $sCount To 1 Step -1

    $aEvent = _EventLog__Read($hLog, True, False, $i)

    If StringInStr($aEvent[13], "PowerBroker for Windows detected a UAC prompt") Then

        ;MsgBox(0, "Record Number: " & $aEvent[1], "Submitted: " & $aEvent[2] & " " & $aEvent[3] & @CRLF & "Description: " & $aEvent[13])
        FileWriteLine($hFileOpen, "Record Number: " & $aEvent[1] & @CRLF & "Submitted: " & $aEvent[2] & " " & $aEvent[3] & @CRLF & "Description: " & $aEvent[13] & @CRLF & @CRLF)

    EndIf

Next

FileClose($hFileOpen)

However the output is not very nice.

How can i make the "Description" array easier to read in the text file?  Right now it is all one line.

PB_UAC_Prompt.txt

Link to comment
Share on other sites

antmar,

Right now it is all one line.

 

The output text for Description is not one line, however, each line is terminated by a CR (as oppossed to a CRLF). 

You can change that by changing all CR's to CRLF's. 

Somehting like this...

$aEvent[13] = stringreplace($aEvent[13],@CR,@CRLF)

I can't test anything as I don't have UAC on.

edit: Note, in this case it works because the string you are changing only contains CR's.  This will NOT work for strings containing a mix of CR's and CRLF's.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

  • Moderators

antmar, the forum etiquette is to wait 24 hours before bumping your thread. We are all volunteers here, and there are several forums through which we scan for questions. Waiting 24 hours gives us enough time to review the issue and offer suggestions :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@JLogan

You are right, sorry about that.  Just anxious to get my script working.

@kylomas

I made the change and altered the text before writing to the file however the format is not right yet.

I would like the "Record Number" to be the first line written and all the rest with "Authorization" being the last line written before the next record is written.

Here is the current output file:

 

PBUACEvents.txt

Link to comment
Share on other sites

Glad you got it working...note - "Authorization" is not always the last line of a record (see the first record of the file you posted)

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...