Jump to content
DH

Function WinActivate not always work

Recommended Posts

DH

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.

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
DH

Hello water,

So you think the problem is caused by WinWaitActive, but not WinActivate ?

Should I modify like this

$status = 1
While $status = 1
    If WinWaitActive("Title", "text") <> 0 Then
        Send("!n")
        $status = 0
    Else
       WinActivate("Title", text")
    EndIf
WEnd

 

Edited by DH

Share this post


Link to post
Share on other sites
DH

Just want to say the above modified code is not work

Share this post


Link to post
Share on other sites
Jos

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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
DH

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.

 

Share this post


Link to post
Share on other sites
ViciousXUSMC

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}")

 

Share this post


Link to post
Share on other sites
ViciousXUSMC

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

 

Share this post


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

×