DLynam 0 Posted December 18, 2020 Hello World, I am automating some software installations, and on a small subset of our machines, the installer we run needs a Microsoft C++ Redistributable. I have set the following code as my if loop: If WinExists("MagTek HID Secure Card Reader Authenticator API Setup") Then WinActivate("MagTek HID Secure Card Reader Authenticator API Setup") Sleep(2000) MouseClick('primary', 152, 220, 1, 0) WinWait("Microsoft Visual C++ 2010 X86 Redistributable Setup") MouseClick('primary', 52, 265, 1, 0) Sleep(2000) MouseClick('primary', 365, 446, 1, 0) WinWait("Microsoft Visual C++ 2010 x86 Redistributable Setup", "Installation Is Complete") WinActivate("Microsoft Visual C++ 2010 x86 Redistributable Setup", "Installation Is Complete") MouseClick('primary', 439, 446, 1, 0) EndIf This works if the condition is met, however when the window does not pop up, the code will not run any further. Previous to this, I have a WinWait setup to timeout after 10 seconds to see if the MagTek window shows up, and that works. The whole script runs if I take this if loop out, however that defeats the purpose of having the if loop there. Anybody able to see what I'm missing? Share this post Link to post Share on other sites
JockoDundee 156 Posted December 18, 2020 1 hour ago, DLynam said: Anybody able to see what I'm missing? The actual loop. 1 hour ago, DLynam said: The whole script runs if I take this if loop out, however that defeats the purpose of having the if loop there. “If's” are not loops. This, OTOH, loops forever: While True If WinExists("MagTek HID Secure Card Reader Authenticator API Setup") Then WinActivate("MagTek HID Secure Card Reader Authenticator API Setup") Sleep(2000) MouseClick('primary', 152, 220, 1, 0) WinWait("Microsoft Visual C++ 2010 X86 Redistributable Setup") MouseClick('primary', 52, 265, 1, 0) Sleep(2000) MouseClick('primary', 365, 446, 1, 0) WinWait("Microsoft Visual C++ 2010 x86 Redistributable Setup", "Installation Is Complete") WinActivate("Microsoft Visual C++ 2010 x86 Redistributable Setup", "Installation Is Complete") MouseClick('primary', 439, 446, 1, 0) EndIf Sleep(1000) WEnd Change the While True to whatever condition you want to exit the loop. 2 FrancescoDiMuro and DLynam reacted to this Code hard, but don’t hard code... Share this post Link to post Share on other sites
Aelc 25 Posted December 18, 2020 (edited) well i would use something like _WinExistAct("MagTek HID Secure Card Reader Authenticator API Setup") If @error Then _Error() MouseClick("primary", 152, 220, 1, 0) _WinExistAct("Microsoft Visual C++ 2010 X86 Redistributable Setup") If @error Then _Error() MouseClick("primary", 52, 265, 1, 0) Sleep(2000) MouseClick("primary", 365, 446, 1, 0) _WinExistAct("Microsoft Visual C++ 2010 X86 Redistributable Setup", "Installation Is Complete") If @error Then _Error() MouseClick('primary', 439, 446, 1, 0) Func _Error() MsgBox(48, "error", "timeout reached") Exit EndFunc ;==>_Error Func _WinExistAct($title, $text = "", $timeout = 10) $timeout = $timeout * 1000 Local $timer = TimerInit() Do Sleep(50) Local $diff = TimerDiff($timer) Until WinExists($title, $text) Or $diff >= $timeout If $timer > $timeout Then Return SetError(-1, 0, -1) If Not WinActive($title, $text) Then WinActivate($title, $text) Return 0 EndFunc ;==>_WinExistAct and also i would use ControlClick and ControlGetText in a do until loop to check if controls exist when it's same title of the window, instead of using mouseclick and sleep - to be fast as possible... like this you are always waiting 2 seconds. if the installer finished or not. maybe some people have slower or faster PCs and then this doesn't work anymore or it takes more time as necessary Edited December 18, 2020 by Aelc 1 DLynam reacted to this why do i get garbage when i buy garbage bags? Share this post Link to post Share on other sites
JockoDundee 156 Posted December 19, 2020 (edited) 7 hours ago, Aelc said: well i would use something like Fwiw, the second window WinWait("Microsoft Visual C++ 2010 X86 Redistributable Setup") does not get activated before the click is sent, in the OPs version. Maybe it doesn’t matter, maybe it does. Edited December 19, 2020 by JockoDundee 1 DLynam reacted to this Code hard, but don’t hard code... Share this post Link to post Share on other sites
DLynam 0 Posted January 5 On 12/18/2020 at 11:55 AM, JockoDundee said: The actual loop. “If's” are not loops. This, OTOH, loops forever: While True If WinExists("MagTek HID Secure Card Reader Authenticator API Setup") Then WinActivate("MagTek HID Secure Card Reader Authenticator API Setup") Sleep(2000) MouseClick('primary', 152, 220, 1, 0) WinWait("Microsoft Visual C++ 2010 X86 Redistributable Setup") MouseClick('primary', 52, 265, 1, 0) Sleep(2000) MouseClick('primary', 365, 446, 1, 0) WinWait("Microsoft Visual C++ 2010 x86 Redistributable Setup", "Installation Is Complete") WinActivate("Microsoft Visual C++ 2010 x86 Redistributable Setup", "Installation Is Complete") MouseClick('primary', 439, 446, 1, 0) EndIf Sleep(1000) WEnd Change the While True to whatever condition you want to exit the loop. Hey, thanks! This worked. I'm new to autoit (coming from a python background where if is a loop by itself) and didn't realize that's how this worked. Cheers! Share this post Link to post Share on other sites
water 2,386 Posted January 5 Doesn't the software you install provide a silent installation option? This way you would not need to automate the GUI. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
DLynam 0 Posted January 5 Just now, water said: Doesn't the software you install provide a silent installation option? This way you would not need to automate the GUI. Only one does, we are dealing with a series of about a dozen or so installers, and only one is silent. I don't have the skill or time to create silent installers for all of them. If you have ideas, feel free to suggest, but I've been told to work with what I've got. `\('-')/` Share this post Link to post Share on other sites
water 2,386 Posted January 5 Most of the installers when called with one of the following parameters ("/?", "-?", "/help" or "-help") will provide a list of available command line switches. One of them might allow a silent installation. Which applications do you need to install? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites