Jump to content

Function WinActivate not always work


DH
 Share

Recommended Posts

I use AutoIt to kick off those nasty application installer which has no silent install feature.

It's OK to execute only 1 installer. But not always work if I need to execute several installer in sequence. (I use Microsoft MDT to make them execute in sequence)

Codes are simple.

First,

Run("setup.exe")

Second,

WinWait("The title", "Some text")

Third,

If WinExists("The title", "Some text") Then
WinActivate("The title", "Some text")
WinWaitActive("The title", "Some text")

Fourth, here do the action such as

Send("!n")
Send("{ENTER}")

The 1st installer always success. The 2nd one sometime. Never make it to the 3rd.

The problem is, WinActivate seems can focus to the target window (because I saw the installer icon flash few times at the taskbar), but then stop.

Then I manually click on the target window, it start to run the remaining scripts. This indicate that it was waiting for the target window to be activate.

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Do it in a While loop. Check the return value of WinWaitActive and exit the loop on success.

Edited by water

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

  • Developers

That doesn't look right. WinWaitActive() will wait forever since there is no timeout specified, so guess that should be a WinExists()?

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi Jos,

My situation is I got 3 application installer (e.g. abcsetup.exe, defsetup.exe and ghisetup.exe)

And I made 3 autoit to execute each of them (e.g. abcauto.exe, defauto.exe and ghi.exe)

Then use Microsoft MDT to execute those 3 autoit exe in sequence.

The weird thing is the scripts never has problem if I just run a single exe file.

But in sequence, the first one never fail. It usually fail start from the 2nd one.

 

Link to comment
Share on other sites

I have never had an issue with just WinWait() and WinActivate() I never needed to use WinWaitActive()

Since your 2nd Script already waited for the window for an infinite amount of time, there is no need to check for it in the 3rd part of the script. 

 

So I would just strip it down to this:

Run("setup.exe")
WinWait("The title", "Some text")
WinActivate("The title", "Some text")
Send("!n")
Send("{ENTER}")

If you wanted a conditional so that it loops so many times and exits add a loop with a If WinExists() but a more simple way for this kind of script is to just add a timeout value to your WinWait.

 

Run("setup.exe")
;Look for Window for 10 Seconds if Not Found Exit Scirpt
If WinWait("The title", "Some text", 10) = 0 Then Exit
WinActivate("The title", "Some text")
Send("!n")
Send("{ENTER}")

 

Link to comment
Share on other sites

Hi Jos,

My situation is I got 3 application installer (e.g. abcsetup.exe, defsetup.exe and ghisetup.exe)

And I made 3 autoit to execute each of them (e.g. abcauto.exe, defauto.exe and ghi.exe)

Then use Microsoft MDT to execute those 3 autoit exe in sequence.

The weird thing is the scripts never has problem if I just run a single exe file.

But in sequence, the first one never fail. It usually fail start from the 2nd one.

 

Sounds like your issue may be with your deployment not your script.

What you gave us as an example was just a simple single installer.  If you want to install multiple things in a single script you can do it many ways.  Using the same code I just posted you could do it like this.

 

;Multi Installer

Program1()
Program2()
Program3()

Func Program1() 
    Run("setup1.exe")
    ;Look for Window for 10 Seconds if Not Found Goto Next Function
    If WinWait("The title", "Some text", 10) = 0 Then Return    
    WinActivate("The title", "Some text")
    Send("!n")
    Send("{ENTER}")
EndFunc

Func Program2() 
    Run("setup2.exe")
    ;Look for Window for 10 Seconds if Not Found Goto Next Function
    If WinWait("The title", "Some text", 10) = 0 Then Return    
    WinActivate("The title", "Some text")
    Send("!n")
    Send("{ENTER}")
EndFunc

Func Program3() 
    Run("setup3.exe")
    ;Look for Window for 10 Seconds if Not Found Goto Next Function
    If WinWait("The title", "Some text", 10) = 0 Then Return    
    WinActivate("The title", "Some text")
    Send("!n")
    Send("{ENTER}")
EndFunc

 

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