stev379 Posted May 13, 2009 Share Posted May 13, 2009 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! expandcollapse popup#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 Link to comment Share on other sites More sharing options...
WideBoyDixon Posted May 13, 2009 Share Posted May 13, 2009 Doesn't your _EventLog__Close() need to inside the second For loop? [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
GEOSoft Posted May 13, 2009 Share Posted May 13, 2009 (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 May 13, 2009 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!" Link to comment Share on other sites More sharing options...
stev379 Posted May 13, 2009 Author Share Posted May 13, 2009 EditWhoa 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? Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 13, 2009 Share Posted May 13, 2009 (edited) There is an earlier topic on this issue: < deleted bad link >Valik created a ButTrac for it (doesn't tell you much): #819The 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 May 13, 2009 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 Link to comment Share on other sites More sharing options...
stev379 Posted May 13, 2009 Author Share Posted May 13, 2009 There is an earlier topic on this issue: EventLog.au3 AutoIt crashesValik created a ButTrac for it (doesn't tell you much): #819The 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! 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 13, 2009 Share Posted May 13, 2009 (edited) Phooey! But thanks! 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=89411Works for me, including from the quote in your reply.Edit: Stupid link on my part. I'm researching the correct one... sorry. Edited May 13, 2009 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 Link to comment Share on other sites More sharing options...
stev379 Posted May 13, 2009 Author Share Posted May 13, 2009 (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 May 13, 2009 by stev379 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now