Jump to content

[Ask] Automatically click "OK" in case of an irregularly recurring error message


Recommended Posts

Hallo

I want to restore data from an LTO tape that was unfortunately copied to it incorrectly (there are a lot of small individual files on it). Unfortunately after restoring each individual file such an error message appears:
Beispiel.jpg.d119c18d261bd0ffd69c0d46c8e12168.jpg

Restoration of the files seems to have been executed successfully nevertheless.
Now I have to click over 7000 times to that error to restore the whole tape :(

If I could automate this with Autoit it would help me tremendously. Unfortunately I don't know anything about AutoIt at this time and my attempt to just send a RETURN keystroke regularly doesn't work. There is not even a single keystroke sent (although it works with the RETURN keystroke e.g. in Notepad).

That was this first script:

Sleep (5000)
While True
    Send("{ENTER}")
    Sleep (1000)
WEnd

It is not even necessary to press the button. It would be enough to simply close the alarm window

I don't understand how to wait and send for special "Windows".

I used the Au3Info Program and got the following Information about that error Window:

>>>> Window <<<<
Title:    ch13_20190802000000.mp4
Class:    #32770
Position:    845, 484
Size:    233, 149
Style:    0x94C803C5
ExStyle:    0x00010101
Handle:    0x0000000000360EC2

>>>> Control <<<<
Class:    Button
Instance:    1
ClassnameNN:    Button1
Name:    
Advanced (Class):    [CLASS:Button; INSTANCE:1]
ID:    2
Text:    OK
Position:    132, 88
Size:    80, 23
ControlClick Coords:    38, 10
Style:    0x50030000
ExStyle:    0x00000004
Handle:    0x000000000084153E

>>>> Mouse <<<<
Position:    1018, 608
Cursor ID:    0
Color:    0xE1C17F

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
OK
CRC-Fehler: 0<>C40B7756


>>>> Hidden Text <<<<

The window title changes of course with each file for which this message occurs

For example, I tried the following to close this error-message window:

Sleep (5000)
Local $hWnd = WinWait("[CLASS:#32770]", "", 10)
While True
    ControlClick($hWnd, "", "Button1")
    Sleep (1000)
    WinClose($hWnd)
    Sleep (1000)
WEnd

Does anyone have any idea how I can make this work properly?

 

Link to post
Share on other sites

Sometimes a slightly different message comes up, like this one:
Beispiel.jpg.bc9494317d2bb3958a00072c48d70460.jpg

From Au3Info I got this Infos about that Message Box:

>>>> Window <<<<
Title:  Z-DATdump Restore
Class:  #32770
Position:   834, 471
Size:   257, 149
Style:  0x94C803C5
ExStyle:    0x00010101
Handle: 0x00000000001E1A3A

>>>> Control <<<<
Class:  Button
Instance:   1
ClassnameNN:    Button1
Name:   
Advanced (Class):   [CLASS:Button; INSTANCE:1]
ID: 1
Text:   OK
Position:   71, 88
Size:   80, 23
ControlClick Coords:    46, 16
Style:  0x50030000
ExStyle:    0x00000004
Handle: 0x00000000001C1AF4

>>>> Mouse <<<<
Position:   954, 601
Cursor ID:  0
Color:  0xE1E1E1

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
OK
Abbrechen
autorun.inf:CRC 0<>4C4204CC


>>>> Hidden Text <<<<

 

Link to post
Share on other sites

In some programs, the class will change with every new window that get's created. What you could do instead is detect if the main window (Z-Datdump Restore) becomes unfocussed, something like this:

While (True)

    ; Detect if the window gets unfocussed
    If Not WinActive("INSERT THE MAIN WINDOW HANDLE HERE") Then
    
        ; Check if it is the correct window by determening it's size.
        $aWinSize = WinGetClientSize("[ACTIVE]")
        If $aWinSize[0] == 233 And $aWinSize[1] == 149 Then
        
            ; Click the ok button. Using [ACTIVE] here since you said the title of the error window changes.
            ControlClick("[ACTIVE]", "", "Button1")
        EndIf
    EndIf
WEnd

Hope this helps :)

Edited by Leendert-Jan
Link to post
Share on other sites

Hi thanks.

this does not work because the line...

$aWinSize = WinGetClientSize("[ACTIVE]")

set to the variable $aWinSize nothing i think;

I tried that with the following code:

While (True)

    ; Detect if the window gets unfocussed
    If Not WinActive("Z-DATdump") Then
        
        ; Check if it is the correct window by determening its size.
        $aWinSize = WinGetClientSize("[ACTIVE]")
        
        Msgbox(64,"getWinSize",$aWinSize)
    EndIf
WEnd

and if the error window apears I got the message box without any content.

I tried that, too

While (True)

    ; Detect if the window gets unfocussed
    If Not WinActive("Z-DATdump") Then
        
         WinClose("[ACTIVE]")
       
    EndIf
WEnd

But that doesn't work :(

 

Link to post
Share on other sites

First I want to apologize. I see I made a little mistake in the script. It is not

WinActive("INSERT WINDOW HANDLE HERE")

But

WinActive(HWnd("INSERT WINDOW HANDLE HERE"))

Sorry :). Anyway,

On 12/3/2021 at 1:45 PM, Wise said:

and if the error window apears I got the message box without any content.

WinGetClientSize returns an array. A messagebox cannot display an array. Try using _ArrayDisplay instead to get it's content:

#include <Array.au3>

ConsoleWrite("Make window active.")
Sleep(2000)

$aWinSize = WinGetClientSize("[ACTIVE]")
_ArrayDisplay($aWinSize)

 

On 12/3/2021 at 1:45 PM, Wise said:

I tried that, too

While (True)

    ; Detect if the window gets unfocussed
    If Not WinActive("Z-DATdump") Then
        
         WinClose("[ACTIVE]")
       
    EndIf
WEnd

But that doesn't work

You are using "Z-DATdump" in WinActive. That is the title of the main window, so under normal circumstances that would be correct. But I saw in your screenshots that some error windows also have that title. Hence, the script will keep looping, because it still sees a window with that title.

What I meant to say was that instead of using a title (which might bug because there can be multiple windows with the same title) you can use the Handle of the window.

This script should detect that the main window get's unfocussed.

While (True)

    ; Detect if the window gets unfocussed
    If WinActive(HWnd("INSERT THE MAIN WINDOW HANDLE HERE")) Then
        ConsoleWrite("Active" & @CRLF)
    Else
        ConsoleWrite("Inactive" & @CRLF)
    EndIf
    
    Sleep(1000)
WEnd

You can get the window handle by using the Window Info tool:

>>>> Window <<<<
Title:    TestWindow
Class:    WindowsForms10.Window.8.app.0.378734a_r3_ad1
Position:    87, 85
Size:    433, 431
Style:    0x16CB0000
ExStyle:    0x00050100
Handle:    0x0000000000100BA8

At the bottom it says Handle. That is the value you want to use.

Note: The Window Handle might be different every time the program starts.

More info:

_ArrayDisplay: https://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayDisplay.htm

HWnd: https://www.autoitscript.com/autoit3/docs/functions/HWnd.htm

WinGetClientSize: https://www.autoitscript.com/autoit3/docs/functions/WinGetClientSize.htm

Edited by Leendert-Jan
Changed the window info to something different that the error window, it might be a bit confusing
Link to post
Share on other sites

Hi Wise,

Does this work?

While 1
    Local $hWnd = WinWait('[CLASS:#32770]', '', 1)
    If IsHWnd($hWnd) = 1 Then
        If WinActive($hWnd) = 0 Then WinActivate($hWnd)
        Local $iState = WinGetState($hWnd)
        If BitAND($iState, $WIN_STATE_EXISTS) And _
           BitAND($iState, $WIN_STATE_VISIBLE) And _
           BitAND($iState, $WIN_STATE_ENABLED) And _
           BitAND($iState, $WIN_STATE_ACTIVE) Then
            ControlClick($hWnd, '', '[CLASS:Button; INSTANCE:1]')
        Else
            WinKill($hWnd)
        EndIf
        WinWaitClose($hWnd, '', 3)
    EndIf
    Sleep(1000)
WEnd

 

Link to post
Share on other sites

I once had a similar problem with a compiled script running on a server. In rare cases a MsgBox would pop up and bring the script to a permanent halt.
Trancexx provided a solution:

http://www.autoitscript.com/forum/topic/143250-grab-runtime-errors-when-script-is-run-from-a-service/

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 (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

try this code:(again i did little mistake i did fixed ihope it's works for ya)

Global $aListe;
Global $ADD
Global $data
Global $xw
Global $sae  = 1 ? 1;;true
Global $st
           Global $Prev,$Preva;
           ;Z-DATdump Restore <- title of window
           ;MessageBox Text <- "autorun.inf:CRC 0<>4C4204CC"
           _NoMessage("Z-DATdump Restore","autorun.inf:CRC 0<>4C4204CC")
           ;this code made by Ad777
           ;$TextIn; the text inside MessageBox
           ;$Window Title :the title of window(not MessageBox Title)
Func _NoMessage($WindowTitle,$TextIn,$class = "Static")
    WinWaitActive($WindowTitle)
     While 1
        ;if WinActive($WindowTitle) Then
        $aListe = WinList();
               For $iae = 1 To $aListe[0][0] Step 1

                      If $aListe[$iae][0] <> "" And BitAND(WinGetState($aListe[$iae][1]), 2) Then
                         if $aListe[$iae][0] = $WindowTitle Then
                            $ADD &= $aListe[$iae-1][0]
                         EndIf
                  $Preva &= $aListe[$iae][0];;
                  $xw =$ADD
                          For $i = 0 To 15 Step 1
                  if ControlGetText($xw,"",$class&$i) = $TextIn And WinActive($xw) Then

    WinKill($xw)
 EndIf
 Next
                  EndIf
               Next
                   if $sae = 1  Then
                   $Prev = $Preva ;;;
                $sae = 1 ? 0;false
                   EndIf
                   if _WindowIn($WindowTitle) = 1 Then
                       if $Preva = $Prev  Then
;;;if it's equal do stufff

             EndIf
          EndIf
                    ;          $state = "off"

$iae = 0
               $Preva = ""

               $ADD = ""
  if _WindowIn($WindowTitle) = 0 Then
     $Prev = "";
               Local $aList = WinList()
    For $i = 1 To $aList[0][0]
        If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then
           $Prev &= $aList[$i][0]
EndIf
    Next
 EndIf
; EndIf
WEnd
EndFunc

 Func _WindowIn($MainGui)

 $PX = MouseGetPos()[0]
   $WX = WinGetPos($MainGui)[0]
   $PY = MouseGetPos()[1]
   $WY = WinGetPos($MainGui)[1]
local $Wd = WinGetClientSize($MainGui)[0]+$WX+2
local $Wh = WinGetClientSize($MainGui)[1]+$WY+25
local $Wh2 = WinGetClientSize($MainGui)[1]-$Wh
if  $PX >= $WX  and $PY >= $WY+26 and $PY < $Wh And $PY > $Wh2 and $PX <= $Wd then; And $WY <$PY Then
Return 1
 Else
 Return 0
EndIf
EndFunc

 

Edited by ad777

iam ِAutoit programmer.

best thing in life is to use your Brain to

Achieve

everything you want.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...