Jump to content

If loop killing script


DLynam
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.

Code hard, but don’t hard code...

Link to comment
Share on other sites

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 by Aelc

why do i get garbage when i buy garbage bags? <_<

Link to comment
Share on other sites

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 by JockoDundee

Code hard, but don’t hard code...

Link to comment
Share on other sites

  • 3 weeks later...
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!

Link to comment
Share on other sites

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 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

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. `\('-')/`

Link to comment
Share on other sites

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 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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...