Sign in to follow this  
Followers 0
stev379

_EventLog__Read() - AutoIT crash

8 posts in this topic

I've tested this on 5 different Physical and VM machines varying between XP Pro Sp2 and Vista SP1. It worked on one XP machine, but crashes after starting the second round in the second For loop.

Any idea why it's crashing or how to get it to continue to loop through the logs?

Thanks!

#include <GuiConstantsEx.au3>
#include <EventLog.au3>

Global $iMemo
Const $ReadfromNewestRecordFirst                    =  False
Const $ReadfromNewestRecordLast                     =  True
Const $QueryStartTime                               =  _Nowdate()

MsgBox( 0, 'EventLog Query test', 'About to call _EventLog_Report')

_EventLog_Report()

Func _EventLog_Report()
    Local $hEventLog, $hGUI, $aEvent
    Dim $aLogType[2] = ['Application', 'System']
    
    For $n = 0 to 1 
        $hEventLog = _EventLog__Open('', $aLogType[$n]) ;, True, $ReadfromNewestRecordFirst)
        MsgBox(0,'$aLogType[$n]', $aLogType[$n])
        $File = FileOpen(@ScriptDir & '\EventLog_' & $aLogType[$n] & '.log', 2)
        FileWriteLine($File, $aLogType[$n] & ' Event Log query started at ' & _NowCalc() & @CRLF & @CRLF)
        $EventLog_COUNT = _EventLog__Count($hEventLog)
    
        For $i = 0 to $EventLog_COUNT       ; loops through here once and displays all the MsgBoxes in the loop, 
                                          ; but crashes before displaying the MsgBox below as it starts this loop the second time.
            MsgBox(0,'$EventLog_COUNT', $EventLog_COUNT)
            Dim $aEvent = _EventLog__Read($hEventLog)
            MsgBox( 0, '$aEvent[8]', $aEvent[8])
    
            If $aEvent[8] = 'Error' Or $aEvent[8] = 'Warning' Then
                $LogResults = 'Type ..............: ' & $aEvent[ 8] & @CRLF & _
                              'Result ............: ' & $aEvent[ 0] & @CRLF & _
                              'Record number .....: ' & $aEvent[ 1] & @CRLF & _
                              'Result ............: ' & $aEvent[ 0] & @CRLF & _
                              'Record number .....: ' & $aEvent[ 1] & @CRLF & _
                              'Submitted .........: ' & $aEvent[ 2] & ' ' & $aEvent[ 3] & @CRLF & _
                              'Generated .........: ' & $aEvent[ 4] & ' ' & $aEvent[ 5] & @CRLF & _
                              'Event ID ..........: ' & $aEvent[ 6] & @CRLF & _ 
                              'Category ..........: ' & $aEvent[ 9] & @CRLF & _
                              'Source ............: ' & $aEvent[10] & @CRLF & _
                              'Computer ..........: ' & $aEvent[11] & @CRLF & _
                              'Username ..........: ' & $aEvent[12] & @CRLF & _
                              'Description .......: ' & $aEvent[13] & @CRLF & _
                              '*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*' & @CRLF & @CRLF
        
                    MsgBox(0,'', $LogResults)                   
                    ;FileWriteLine($File, $LogResults)
            EndIf               
            MsgBox(0,'', 'Exited if statement after displaying results')    
        Next                
            MsgBox(0,'', 'Exited For loop after displaying results - About to write to $File.')                 
            Sleep(10)
            FileWriteLine($File, $aLogType[$n] & ' Event Log query completed at ' & _NowCalc())
            Fileclose($File)
    Next        
    _EventLog__Close($hEventLog)
    MsgBox(64, 'Event Log Query', 'Event Log query complete.')
EndFunc

Share this post


Link to post
Share on other sites



Doesn't your _EventLog__Close() need to inside the second For loop?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

a couple of things that have the potential to cause an issue primarily it's a matter of error checking. Always make sure that you are covered for the unexpected.

Change the For $n = 0 to 1

For $n =0 To Ubound($n) -1;; Better habit to get into

Change $File = FileOpen(@ScriptDir & '\EventLog_' & $aLogType[$n] & '.log', 2)

$File = @ScriptDir & '\EventLog_' & $aLogType[$n] & '.log'
If NOT FileExists ($File) Then ContinueLoop
$hFile = FileOpen($File, 2)
If $hFile = -1 Then
    MsgBox(0, "Error",  There was a problem opening " & $File & " for reading")
    ContinueLoop
EndIf

Change FileWriteLine($File, $aLogType[$n] & ' Event Log query started at ' & _NowCalc() & @CRLF & @CRLF)

FileWriteLine($hFile, $aLogType[$n] & ' Event Log query started at ' & _NowCalc() & @CRLF & @CRLF)

Change Fileclose($File) to

FileClose($hFile)

Edit

Whoa up there! This line may be causing an issue

$EventLog_COUNT = _EventLog__Count($hEventLog)

How are you getting the count in that function? If you are using any type of file read then you have to close the file handle before you do the read. A file can NOT be open in two modes at the same time.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Edit

Whoa up there! This line may be causing an issue

$EventLog_COUNT = _EventLog__Count($hEventLog)

How are you getting the count in that function? If you are using any type of file read then you have to close the file handle before you do the read. A file can NOT be open in two modes at the same time.

Thanks!

I'm testing the code changes now.

Re: $EventLog_COUNT = _EventLog__Count($hEventLog)

I don't understand. It's opening the event log to read from and also to count the number of log records, but it's opening a text (.log) file to write to.

Why would either need to be closed?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

There is an earlier topic on this issue: < deleted bad link >

Valik created a ButTrac for it (doesn't tell you much): #819

The fix will come out in the new 3.3.1.0 Beta, but it was also posted in the earlier topic linked above.

:)

Edit: Deleted bad link, looking for the corrected one, and corrected future Beta version number.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

There is an earlier topic on this issue: EventLog.au3 AutoIt crashes

Valik created a ButTrac for it (doesn't tell you much): #819

The fix will come out in the new 3.2.1.0 Beta, but it was also posted in the earlier topic linked above.

:)

Phooey! But thanks! :party:

I was so close to complete with VB, but preferred AutoIT so I could more easily GUI the whole thing with options.

Any idea on the ETA for the Beta?

FYI - The first link appears to be dead.

http://www.autoitscript.com/forum/index.php?showtopic=89411

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Phooey! But thanks! :party:

I was so close to complete with VB, but preferred AutoIT so I could more easily GUI the whole thing with options.

Any idea on the ETA for the Beta?

We await the good pleasure of the Jon, whose ways are a mystery to mere mortals like us.

FYI - The first link appears to be dead.

http://www.autoitscript.com/forum/index.php?showtopic=89411

Works for me, including from the quote in your reply.

Edit: Stupid link on my part. I'm researching the correct one... sorry.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

We await the good pleasure of the Jon, whose ways are a mystery to mere mortals like us.

Works for me, including from the quote in your reply.

You don't have to wait for the Beta to come out, however. Valik's patched version was posted at: EventLog.au3

:)

So close I can taste it. Neither link works for me. Are the links on the same network you're on maybe? I'm taking shots in the dark.

The error returned was:

Sorry, the link that brought you to this page seems to be out of date or broken.

I hate to ask if it's already posted, but can you post the code in this thread?

It's a permission error on this link: http://www.autoitscript.com/forum/index.ph...st&id=24643

The error returned was:

Sorry, but you do not have permission to use this feature. If you are not logged in, you may do so using the form below if available.

Can the code be copied\moved to a location where regular users can gain access?

Thanks!!

Edited by stev379

Share this post


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
Sign in to follow this  
Followers 0