Docfxit Posted March 13, 2023 Share Posted March 13, 2023 (edited) I would like to click on the continue button every time this windows cums up. This is what AutoIt sees: This is what I have for code that isn't working: Opt("WinTitleMatchMode", 4) Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 0) AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{F8}", "Terminate") Local $sWindowsTitle = "[CLASS:##32770]" ;Set The Window title Here While 1 If WinExists("Error Applying Security", "An error occurred while applying security information") Then WinActivate("Error Applying Security", "An error occurred while applying security information") WinWaitActive("Error Applying Security", "An error occurred while applying security information") ControlSend("Error Applying Security", "&Continue", "1", "{ENTER}") EndIf Sleep(8000) WEnd Func Terminate() Exit 0 EndFunc ;==>Terminate Edited March 13, 2023 by Docfxit Link to comment Share on other sites More sharing options...
mistersquirrle Posted March 13, 2023 Share Posted March 13, 2023 (edited) Try using ControlClick instead of ControlSend. If you want to use ControlSend, you may need to also use ControlFocus first as well. Here's a modification to your script for how I would go about it: Opt("WinTitleMatchMode", 4) Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 0) AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{F8}", "Terminate") Global $sWindowsTitle = "[TITLE:Error Applying Security;CLASS:#32770]" ;Set The Window title Here Global $sWinText = "An error occurred while applying security information" ; Make sure to check the 'Visible Text' tab in the window info to see if it actually exists on the window/msgbox before you try to use it Global $hWnd While 1 $hWnd = WinGetHandle($sWindowsTitle) If Not @error Then ; Alternative method to WinExists, now we have the window handle if it did exist, so we can make sure we're referencing the same one in the other functions Do WinActivate($hWnd) Sleep(100) ; Avoid high CPU usage Until WinActive($hWnd) ; Keep trying to activate the window until it is active ControlClick($hWnd, '', 'Button1', 'main', 1) Sleep(100) ; Give the window some extra time to close after we click the button EndIf Sleep(100) ; You don't need a high sleep, in most cases Sleep(10) will result in 0% CPU usage (though not here) WEnd Func Terminate() Exit 0 EndFunc ;==>Terminate Also keep in mind that you're not using any MouseClick or other Mouse functions, however you have MouseCoordMode set to 0, which changes the default behavior of it. The default is 1 - absolute screen coordinates, 0 is relative coords to the active window, however ControlClick is NOT affected by this setting, since everything is control/window based for it. Edited March 13, 2023 by mistersquirrle We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Docfxit Posted March 13, 2023 Author Share Posted March 13, 2023 Thank you very much for putting that together... It does find the window because I put a Msgbox just before the ControlClick and it does pop up. It doesn't click on the &Continue button though. Any suggestions? Link to comment Share on other sites More sharing options...
Solution mistersquirrle Posted March 14, 2023 Solution Share Posted March 14, 2023 Instead of 'Button1' for the ControlClick, try one of these: ControlClick($hWnd, '', 'Button', 'main', 1) ControlClick($hWnd, '', '[CLASS:Button; INSTANCE:1]', 'main', 1) ControlClick($hWnd, '', 1, 'main', 1) Alternatively, if it doesn't matter if you click Continue or Cancel you could try just using WinClose or WinKill, though I imagine Continue makes it skip over the current item and continue processing, so those may not be options for you. Docfxit 1 We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Docfxit Posted March 14, 2023 Author Share Posted March 14, 2023 (edited) Thank you for the suggestion... None of them worked. I do need to click on continue because there are thousands of them. Edited March 14, 2023 by Docfxit Link to comment Share on other sites More sharing options...
Docfxit Posted March 14, 2023 Author Share Posted March 14, 2023 I added: #RequireAdmin And it's working. Thank you very very much. mistersquirrle 1 Link to comment Share on other sites More sharing options...
Docfxit Posted March 14, 2023 Author Share Posted March 14, 2023 (edited) It's stopping after a the window comes up a few times On line 10 The sleep Edited March 14, 2023 by Docfxit Link to comment Share on other sites More sharing options...
Docfxit Posted March 14, 2023 Author Share Posted March 14, 2023 I changed the sleep just before the endif to 400 and that fixed it. Thank you, Link to comment Share on other sites More sharing options...
mistersquirrle Posted March 14, 2023 Share Posted March 14, 2023 (edited) Do you know where it's stopping? Is it failing to detect the window? Or failing to click? If it's failing to find the window, double check the Window Info. Failing to click, double check the Button control information. Try this, added a little lite logging and relaxed the window matching conditions: expandcollapse popup#RequireAdmin Opt("WinTitleMatchMode", 2) ; 2 - Match any substring in the title Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 0) AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{F8}", "Terminate") ;~ Global $sWindowsTitle = "[TITLE:Error Applying Security;CLASS:#32770]" ;Set The Window title Here Global $sWindowsTitle = "Error Applying Security" ;Set The Window title Here Global $sWinText = "An error occurred while applying security information" ; Make sure to check the 'Visible Text' tab to see if it actually exists Global $aCtrlButtonsToClick[] = ['[CLASS:Button; INSTANCE:1]', 'Button1', 'Button', 1] Global $hCtrl Global $hWnd While 1 $hWnd = WinGetHandle($sWindowsTitle) If Not @error Then ; Alternative method to WinExists, now we have the window handle if it did exist, so we can make sure we're referencing the same one in the other functions __ConsoleLog('Found window: ' & $hWnd & ', title: ' & WinGetTitle($hWnd) & ', text: ' & WinGetText($hWnd)) Do __ConsoleLog('Activating window') WinActivate($hWnd) Sleep(100) ; Avoid high CPU usage Until WinActive($hWnd) Or Not WinExists($hWnd) ; Keep trying to activate the window until it is active __ConsoleLog('Attempting to click button') While WinExists($hWnd) For $iButton = 0 To UBound($aCtrlButtonsToClick) - 1 $hCtrl = ControlGetHandle($hWnd, '', $aCtrlButtonsToClick[$iButton]) If Not @error Then ControlFocus($hWnd, '', $hCtrl) __ConsoleLog('ControlClick (' & $aCtrlButtonsToClick[$iButton] & '; Hnd: ' & $hCtrl & ') result: ' & ControlClick($hWnd, '', $hCtrl, 'main', 1)) EndIf Next Sleep(250) WEnd Sleep(250) ; Give the window some extra time to close after we click the button EndIf Sleep(100) ; You don't need a high sleep, in most cases Sleep(10) will result in 0% CPU usage (though not here) WEnd Func Terminate() Exit 0 EndFunc ;==>Terminate Func __ConsoleLog($sMsg) Local Static $sPrevMsg = '' If $sPrevMsg == $sMsg Then Return True ConsoleWrite($sMsg & @CRLF) $sPrevMsg = $sMsg Return True EndFunc ;==>__ConsoleLog Edit: Glad it's working, upped the sleep in this updated example Edited March 14, 2023 by mistersquirrle Updated code We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Docfxit Posted March 14, 2023 Author Share Posted March 14, 2023 Thank you for creating that. This one seems to work now. ControlClick($hWnd, '', 1, 'main', 1) Although it didn't work before unless I changed the sleep to 400 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