Ticket #2887: COMcrash.au3

File COMcrash.au3, 2.0 KB (added by anonymous, 6 years ago)

minimal and standalone script that crashes AutoIt

Line 
1#include <MsgBoxConstants.au3>
2
3; AutoIt 3.1.1.x beta
4;
5; COM Test File
6;
7; Testing Error Event handling by creating a WMI exception
8
9Local $sMyCompName = @ComputerName
10
11; Initialize my error handler
12Global $g_nComError, $g_oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
13
14; Open WMI
15Local $oWMIservice = ObjGet("winmgmts:\\" & $sMyCompName & "\root\cimv2")
16
17; Check is WMI opened successfully
18If @error Then
19        MsgBox($MB_SYSTEMMODAL, "AutoItCOM Test", "Error getting object $oWMIservice. Error code: " & @error)
20        Exit
21EndIf
22
23; Here are the lines of code that cause the crash:
24;workaround: $g_oMyError = Null
25$g_oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
26; Try a query
27Local $oColProcessors = $oWMIservice.ExecQuery("Select * from Win32_Processor")
28;workaround: $g_oMyError = Null
29$g_oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
30; The crash occurs after this line.
31
32; THIS line should deliberately fail!
33Local $vItem1 = $oColProcessors.item(1)
34
35If $g_nComError Then
36        MsgBox($MB_SYSTEMMODAL, "AutoItCOM test", "Test passed: We got an error number: 0x" & Hex($g_nComError))
37Else
38        MsgBox($MB_SYSTEMMODAL, "AutoItCOM test", "Test failed!")
39EndIf
40
41Exit
42
43; This is my custom error handler
44Func MyErrFunc()
45        Local $sHexNumber = Hex($g_oMyError.number, 8)
46
47        MsgBox($MB_SYSTEMMODAL, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
48                        "err.description is: " & @TAB & $g_oMyError.description & @CRLF & _
49                        "err.windescription:" & @TAB & $g_oMyError.windescription & @CRLF & _
50                        "err.number is: " & @TAB & $sHexNumber & @CRLF & _
51                        "err.lastdllerror is: " & @TAB & $g_oMyError.lastdllerror & @CRLF & _
52                        "err.scriptline is: " & @TAB & $g_oMyError.scriptline & @CRLF & _
53                        "err.source is: " & @TAB & $g_oMyError.source & @CRLF & _
54                        "err.helpfile is: " & @TAB & $g_oMyError.helpfile & @CRLF & _
55                        "err.helpcontext is: " & @TAB & $g_oMyError.helpcontext _
56                        )
57
58        $g_nComError = $g_oMyError.number
59EndFunc   ;==>MyErrFunc