Jump to content

OnDebugMsgBox ( for the dreaded "AutoIt Error" msgbox )


argumentum
 Share

Recommended Posts

OnDebugMsgBox(0_2020_05.24).png.75869501

This is a UDF to handle the AutoIt Error msgbox when our awesome code goes :oops:

I've been using trancexx's code for the longest time and since I iron some wrinkles in my ( personal use ) UDF, decided to organize it in a dignifying way and post it.

The ZIP with the code is in the downloads area.

I'm posting this because most other handlers use /ErrorStdOut to catch errors and they are not that common, for us great coders :king:
So makes little sense to me to run 2 EXEs for something unlikely to happen. No one made a UDF of this, so, I did.

oh, ..there are things where this will be of no use, say, infinite recursion or what not, so, if the the AutoIt Error msgbox was to popup then this UDF should do it.

...let me know if you liked it, or post your views to better it.

Cheers

There is also an EventViewer_GetMyEntries() down this post that may come in handy.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

What's New in Version 1.2020.5.26
added: logfile self maintenance - _DebugMsgBox_PriorLogSize()
added: error return - _DebugMsgBox_AddHookApiError()
fixed: Au3Stripper error on DllCallbackRegister() and related when /RM is used.
added: TimerDiff() and @UserName to the report.
added: _DebugMsgBox_EventLogId() - ( no real use for us here, added for completeness )
added: _DebugMsgBox_EventLogCategory() - ( no real use for us here, added for completeness  )
added: _DebugMsgBox_EventLogBinaryData() - ( no real use for us here, added for completeness  )

What's New in Version 1.2020.5.25
added: _DebugMsgBox_GetUDFversion() ; Get UDF version
added: _DebugMsgBox_EXEversion([$sVersion]) ; Set / Get executable file version for report
fixed: needless folder creations

What's New in Version 1.2020.5.24
initial release

 

The ZIP with the code is in the downloads area.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

The default value for _DebugMsgBox_EventLogId() is 1000, and so is for AutoIt most of the time.
If you want to read your entries from the Events log, you may use these:

#include <EventLog.au3>
#include <Array.au3>


Example1() ; DLL way
Func Example1()
    Local $t = TimerInit(), $aArray = EventLog_FindMyErrorInLast(5)
    If @error Then MsgBox(0, @ScriptName, "there was an error doing this", 10)
    _ArrayDisplay($aArray, "EventLog_FindMyErrorInLast() - w/ DLL - " & TimerDiff($t))
EndFunc   ;==>Example

Func EventLog_FindMyErrorInLast($iMaxReturn = 10, $iMaxSampleCount = 1000, $iEventIdentifier = 1000)
    ; $iMaxReturn = max. records to return
    ; $iMaxSampleCount = max. sample reads searching for events
    ; $iEventIdentifier = _DebugMsgBox_EventLogId()
    Local $hEventLog, $aEvent
    Local $i = 0, $aArray[$iMaxReturn + 1][14]
    $aArray[0][0] = 0
    $aArray[0][1] = "Record number"
    $aArray[0][2] = "Submitted Date Time"
    $aArray[0][4] = "Generated Date Time"
    $aArray[0][6] = "Event ID"
    $aArray[0][7] = "Type #"
    $aArray[0][8] = "Type Str."
    $aArray[0][9] = "Category"
    $aArray[0][10] = "Source"
    $aArray[0][11] = "Computer"
    $aArray[0][12] = "Username"
    $aArray[0][13] = "Description"

    ; Read most current event records
    $hEventLog = _EventLog__Open("", "Application")
    If $hEventLog = 0 Then
        ReDim $aArray[$i + 1][14]
        $aArray[0][0] = $i
        Return SetError(1, 0, $aArray)
    EndIf

    For $n = 1 To $iMaxSampleCount
        $aEvent = _EventLog__Read($hEventLog, True, False)
        If $aEvent[0] = False Then ExitLoop
        If $aEvent[6] <> $iEventIdentifier Or $aEvent[8] <> 'Error' Or $aEvent[9] <> 0 Then ContinueLoop
        $i += 1
        For $m = 1 To 13
            Switch $m
                Case 2, 4
                    $aArray[$i][$m] = $aEvent[$m] & " " & $aEvent[$m + 1]
                Case 3, 5
                    ContinueLoop
                Case Else
                    $aArray[$i][$m] = $aEvent[$m]
            EndSwitch
        Next
        If $i = $iMaxReturn Then ExitLoop
    Next

    _EventLog__Close($hEventLog)

    ReDim $aArray[$i + 1][14]
    $aArray[0][0] = $i
    Return $aArray
EndFunc   ;==>EventLog_FindMyErrorInLast

;=============================================================================


Example2() ; WMI way
Func Example2()  ;  https://www.autoitscript.com/forum/topic/202832-ondebugmsgbox-for-the-dreaded-autoit-error-msgbox/?do=findComment&comment=1456279
    Local $t = TimerInit(), $aArray = EventViewer_GetMyEntries(5)
    If @error Then MsgBox(0, @ScriptName, "there was an error doing this", 10)
    _ArrayDisplay($aArray, "EventViewer_GetMyEntries() - w/ WMI - " & TimerDiff($t))
EndFunc   ;==>Example


Func EventViewer_GetMyEntries($iMaxReturn = 10, $iEventIdentifier = 1000) ; $iMaxReturn = 0 means no limit ;
    ; based out of https://www.autoitscript.com/forum/topic/141626-collecting-event-logs-question/
    Local $v, $r, $s, $iCount = 0, $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
    Local $aOutput[100][7]
    $aOutput[0][1] = "Category"
    $aOutput[0][2] = "RecordNumber"
    $aOutput[0][3] = "Type"
    $aOutput[0][4] = "User"
    $aOutput[0][5] = "TimeGenerated"
    $aOutput[0][6] = "InsertionString(s)"

    Local $objItem, $objWMIService = ObjGet("winmgmts:\\.\")

    Local $sSQL = "SELECT Category,RecordNumber,Type,User,TimeGenerated,InsertionStrings"
    $sSQL &= " FROM Win32_NTLogEvent WHERE "
;~  $sSQL &= "Category = 0 AND " ;   others tend to have Category = 100
    $sSQL &= "Type = 'Error' AND " ;  and Type = 'Information'
    $sSQL &= "EventIdentifier = " & $iEventIdentifier

    Local $colItems = $objWMIService.ExecQuery($sSQL, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        For $objItem In $colItems
            $iCount += 1
            If $iCount = UBound($aOutput) Then ReDim $aOutput[UBound($aOutput) + 100][7]
            $aOutput[$iCount][1] = $objItem.Category
            $aOutput[$iCount][2] = $objItem.RecordNumber
            $aOutput[$iCount][3] = $objItem.Type
            $aOutput[$iCount][4] = $objItem.User
            $aOutput[$iCount][5] = WMIDateStringToDate($objItem.TimeGenerated)
            $s = ""
            $v = $objItem.InsertionStrings
            For $r In $v
                $s &= $r & @CRLF
            Next
            $aOutput[$iCount][6] = $s
            If $iCount = $iMaxReturn Then ExitLoop
        Next
    Else
        ReDim $aOutput[$iCount + 1][7]
        $aOutput[0][0] = $iCount
        Return SetError(1, $iCount, $aOutput)
    EndIf
    ReDim $aOutput[$iCount + 1][7]
    $aOutput[0][0] = $iCount
    Return SetError(0, $iCount, $aOutput)
EndFunc   ;==>EventViewer_GetMyEntries

Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 5, 2) & "/" & _
            StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
             & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2))
EndFunc   ;==>WMIDateStringToDate

 

Edited by argumentum
better code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • 4 weeks later...

Has been added to the wiki :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

What's New in Version 2.2020.6.25
added: _DebugMsgBox_WinVerStr() to set or get the version string for the Windows.
added: Set/Get show of AutoIt version on title when not compiled. Default is True/Show.
    (this is because I've found myself running beta inadvertently and scratching my head)
changed: _DebugMsgBox_LogFile(). now an empty string will overwrite a log in @TempDir,
    to turn it OFF, set to FALSE. ( read remarks )

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • 3 years later...

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

×
×
  • Create New...