Jump to content
Sign in to follow this  
StOnge

Help! - If Statement Depending On Which Window Appears

Recommended Posts

StOnge

Hello. I am working on a script to install a piece of software that will eventually be turned into an .msi and distributed. Some of the computers already have the software installed. I want to create a script that will perform certain commands if the window appears asking them to install, and a different set of commands if the window appears asking if they want to remove the software. I need to do this since some computers already have the software installed.

My idea was to use an If statement. If the computer does not have the software installed, the window appears asking them to install and the install commands will be sent. If the computer does have the software installed, the window appears asking them to repair or remove and a different set of commands will be sent.

Here is my code so far, resulting in an error that says "Line -1: Error: Incorrect number of parameters in function call.":

If WinExists("InsertCompanyAddInSetup" , "Welcome to the InsertCompanyAddIn Setup Wizard" , "Select whether you want to repair or remove") Then 
    Send("!f")
    WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
    Send("!c")
    EndIf
If WinExists("InsertCompanyAddInSetup" , "Welcome to the InsertCompanyAddIn Setup Wizard" , "The installer will guide you through the steps") Then
Send("!n")
WinWaitActive("InsertCompanyAddInSetup" , "Select Installation Folder")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup" , "Confirm Installation")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
Send("!c")

I would great appreciate any assistance that you can give me. Thank you so much for your time and consideration.


www.stonge.com

Share this post


Link to post
Share on other sites
GEOSoft

Go back and read the help file for WinExists(). The first 2 WinExists() statements are incorrect in that you have 3 parameters and there should only be 2.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
StOnge

Oh, I see. That explains the error then. Is there a way to have AutoIT differenciate between two windows that have the same title and heading but different text then?


www.stonge.com

Share this post


Link to post
Share on other sites
herewasplato

Oh, I see. That explains the error then. Is there a way to have AutoIT differenciate between two windows that have the same title and heading but different text then?

I'm not sure what you mean my "heading" but try these types of lines.

If WinExists("Welcome to the InsertCompanyAddIn Setup Wizard" , "Select whether you want to repair or remove") Then ...........

If WinExists("Welcome to the InsertCompanyAddIn Setup Wizard" , "The installer will guide you through the steps") Then ...........


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
GEOSoft

Mr. Senility has given you the correct method. If it's still an issue with certain windows then you could also look at

If StringInStr(WinGetText("Welcome to the InsertCompanyAddIn Setup Wizard"), "some text") Then

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
StOnge

Thank you for your help GEOSoft, but it is still not working. It seems as if the script does not recognize either If statement because it disappears from the system tray right after it opens the setup.exe. This is what my script looks like now:

;Install the SOCO Ribbon
Run("I:\Public\Applications\SOCO Ribbon\setup.exe")
If WinExists("Welcome to the InsertCompanyAddInSetup Setup Wizard" , "Select whether you want to repair or remove") Then 
    Send("!f")
    WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
    Send("!c")
    EndIf
If WinExists("Welcome to the InsertCompanyAddInSetup Setup Wizard" , "The installer will guide you through the steps") Then
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Select Installation Folder")
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Confirm Installation")
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
    Send("!c")

;Copy the Templates 
    DirCopy("I:\Public\Applications\SOCO Ribbon\SOCO Templates" , "C:\Documents and Settings\All Users\Templates\SOCO Templates", 1) 
    EndIf

www.stonge.com

Share this post


Link to post
Share on other sites
herewasplato

Try this:

;Install the SOCO Ribbon
Run("I:\Public\Applications\SOCO Ribbon\setup.exe")
WinWait("Welcome to the InsertCompanyAddInSetup Setup Wizard", "Select whether you want to repair or remove")
Send("!f")
WinWaitActive("InsertCompanyAddInSetup", "Installation Complete")
Send("!c")

WinWait("Welcome to the InsertCompanyAddInSetup Setup Wizard", "The installer will guide you through the steps")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup", "Select Installation Folder")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup", "Confirm Installation")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup", "Installation Complete")
Send("!c")

;Copy the Templates
DirCopy("I:\Public\Applications\SOCO Ribbon\SOCO Templates", "C:\Documents and Settings\All Users\Templates\SOCO Templates", 1)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
StOnge

Try this:

;Install the SOCO Ribbon
Run("I:\Public\Applications\SOCO Ribbon\setup.exe")
WinWait("Welcome to the InsertCompanyAddInSetup Setup Wizard", "Select whether you want to repair or remove")
Send("!f")
WinWaitActive("InsertCompanyAddInSetup", "Installation Complete")
Send("!c")

WinWait("Welcome to the InsertCompanyAddInSetup Setup Wizard", "The installer will guide you through the steps")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup", "Select Installation Folder")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup", "Confirm Installation")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup", "Installation Complete")
Send("!c")

;Copy the Templates
DirCopy("I:\Public\Applications\SOCO Ribbon\SOCO Templates", "C:\Documents and Settings\All Users\Templates\SOCO Templates", 1)oÝ÷ Ûú®¢×«ZZ0²Ø^±Êâ¦Ûh²Ö²{az̬µé­­¬ºØ­v¬m¥êߢ¹'(f§vÂ-®'¶¬jëh×6;Install the SOCO Ribbon
Run("I:\Public\Applications\SOCO Ribbon\setup.exe")
Sleep( 1200 )
If WinActive("Welcome to the InsertCompanyAddInSetup Setup Wizard" , "Select whether you want to repair or remove") Then 
    Send("!f")
    WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
    Send("!c")
    EndIf
If WinActive("Welcome to the InsertCompanyAddInSetup Setup Wizard" , "The installer will guide you through the steps") Then
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Select Installation Folder")
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Confirm Installation")
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
    Send("!c")

;Copy the Templates 
    DirCopy("I:\Public\Applications\SOCO Ribbon\SOCO Templates" , "C:\Documents and Settings\All Users\Templates\SOCO Templates", 1) 
    EndIf

and the result was the script stays in the system tray, but doesn't perform the functions and then disappears. The problems boils down to this. How can I get AutoIT to recognize the difference between this window:

Posted Image

and this window:

Posted Image

Any help would be greatly appreciated. Thanks!


www.stonge.com

Share this post


Link to post
Share on other sites
GEOSoft

Try changing those WinExists() to WinWaitActive() Also it looks like you are after the default in each case so you could just use Send("{Enter}") or better yet get the control Id and use ControlClick()


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
StOnge

I changed the WinExists() to WinWaitActive() and it still just hangs with the script in the system tray. My code looks like this:

;Install the SOCO Ribbon
Run("I:\Public\Applications\SOCO Ribbon\setup.exe")
Sleep( 1200 )
If WinWaitActive("Welcome to the InsertCompanyAddInSetup Setup Wizard" , "Select whether you want to repair or remove") Then 
    Send("!f")
    WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
    Send("!c")
    EndIf
If WinWaitActive("Welcome to the InsertCompanyAddInSetup Setup Wizard" , "The installer will guide you through the steps") Then
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Select Installation Folder")
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Confirm Installation")
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
    Send("!c")

;Copy the Templates 
    DirCopy("I:\Public\Applications\SOCO Ribbon\SOCO Templates" , "C:\Documents and Settings\All Users\Templates\SOCO Templates", 1) 
    EndIf

I really appreciate the help so far. Any other suggestions would be great.


www.stonge.com

Share this post


Link to post
Share on other sites
GEOSoft

This is just off the top of my head and without testing since I don't use MSI and I can't think of any MSI file that I want to run right now. ALSO, check that you are actually sending the right key strokes. Like I said before. If you want the default action just Send("{Enter}") but it's better to use the Windows info tool and get the correct Control ID.

;Install the SOCO Ribbon
Run("I:\Public\Applications\SOCO Ribbon\setup.exe")
Do
Sleep( 1200 )
Until WinActive("Welcome to the InsertCompanyAddInSetup Setup Wizard")
WinWaitActive("Welcome to the InsertCompanyAddInSetup Setup Wizard" , "Select whether you want to repair or remove")
    Send("!f")
    WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
    Send("!c")
WinWaitActive("Welcome to the InsertCompanyAddInSetup Setup Wizard" , "The installer will guide you through the steps")
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Select Installation Folder")
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Confirm Installation")
    Send("!n")
    WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
    Send("!c")

;Copy the Templates 
    DirCopy("I:\Public\Applications\SOCO Ribbon\SOCO Templates" , "C:\Documents and Settings\All Users\Templates\SOCO Templates", 1)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
herewasplato

From your screen shots of the app - I probably picked the wrong two out of three parameters.

title = InsertCompanyAddInSetup

text = Select whether you want to repair or remove

;Install the SOCO Ribbon
Run("I:\Public\Applications\SOCO Ribbon\setup.exe")
WinWait("InsertCompanyAddInSetup" , "Select whether you want to repair or remove")
WinActivate("InsertCompanyAddInSetup" , "Select whether you want to repair or remove")
WinWaitActive("InsertCompanyAddInSetup" , "Select whether you want to repair or remove")
Send("!f")
WinWaitActive("InsertCompanyAddInSetup", "Installation Complete")
Send("!c")


WinWait("InsertCompanyAddInSetup" , "The installer will guide you through the steps")
WinActivate("InsertCompanyAddInSetup" , "The installer will guide you through the steps")
WinWaitActive("InsertCompanyAddInSetup" , "The installer will guide you through the steps")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup", "Select Installation Folder")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup", "Confirm Installation")
Send("!n")
WinWaitActive("InsertCompanyAddInSetup", "Installation Complete")
Send("!c")

;Copy the Templates
DirCopy("I:\Public\Applications\SOCO Ribbon\SOCO Templates", "C:\Documents and Settings\All Users\Templates\SOCO Templates", 1)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
StOnge

Those seem to work to uninstall the program, but not to install. Some of the computers that the script will run on already have the software, in which case I want to do nothing. Some don't have it, in which case I want to install it. So I think I need use an If/Then statement. The basic idea was If this windows appears:

Posted Image

Then Exit.

If this window appears:

Posted Image

Then run the commands to install the program.

Any other ideas?

Edited by StOnge

www.stonge.com

Share this post


Link to post
Share on other sites
StOnge

Posted Image

Is this what you wanted?


www.stonge.com

Share this post


Link to post
Share on other sites
junkew

Does WinWait("InsertCompanyAddInSetup") work for either of the screens?

If yes, most likely the text you check is not there

Workaround: if yes check for the radiobutton existing yes or no.

Or look for the button with Finish with something like below

ControlGetText("InsertCompanyAddInSetup" , "", "[CLASS:Button; TEXT:Finish; INSTANCE:1]")

Share this post


Link to post
Share on other sites
herewasplato

Those seem to work to uninstall the program, but not to install. Some of the computers that the script will run on already have the software, in which case I want to do nothing. Some don't have it, in which case I want to install it. ...

Sorry - I did not pick up on the "if installed then exit" part.

Try this:

;Install the SOCO Ribbon
Run("I:\Public\Applications\SOCO Ribbon\setup.exe")

For $i = 1 To 3000 ;tries for about 15 to 20 minutes and then leaves the loop
    Sleep(300)
    If WinExists("InsertCompanyAddInSetup", "repair or remove") Then
        WinClose("InsertCompanyAddInSetup", "repair or remove")
        WinWaitActive("InsertCompanyAddInSetup", "Installation Complete")
        WinClose("InsertCompanyAddInSetup", "Installation Complete")
        Exit ;exits the entire script
    EndIf

    If WinExists("InsertCompanyAddInSetup", "through the steps") Then
        WinActivate("InsertCompanyAddInSetup", "through the steps")
        WinWaitActive("InsertCompanyAddInSetup", "through the steps")
        Send("!n")
        WinWaitActive("InsertCompanyAddInSetup", "Select Installation Folder")
        Send("!n")
        WinWaitActive("InsertCompanyAddInSetup", "Confirm Installation")
        Send("!n")
        WinWaitActive("InsertCompanyAddInSetup", "Installation Complete")
        WinClose("InsertCompanyAddInSetup", "Installation Complete")
        WinWaitClose("InsertCompanyAddInSetup", "Installation Complete")

        DirCopy("I:\Public\Applications\SOCO Ribbon\SOCO Templates", "C:\Documents and Settings\All Users\Templates\SOCO Templates", 1)
        Exit ;exits the entire script
    EndIf
Next
Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
herewasplato

Mr. Senility ...

:-) :-) :-)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
StOnge

Does WinWait("InsertCompanyAddInSetup") work for either of the screens?

If yes, most likely the text you check is not there

Workaround: if yes check for the radiobutton existing yes or no.

Or look for the button with Finish with something like below

ControlGetText("InsertCompanyAddInSetup" , "", "[CLASS:Button; TEXT:Finish; INSTANCE:1]")

Would the code look like this then?:

If ControlGetText("InsertCompanyAddInSetup" , "", "[CLASS:Button; TEXT:Finish; INSTANCE:1]")  Then 
    Send("!f")
    WinWaitActive("InsertCompanyAddInSetup" , "Installation Complete")
    Send("!c")
    EndIf

www.stonge.com

Share this post


Link to post
Share on other sites
StOnge

Thank you to everyone who offered their time and help with my problem, I finally got it working!

Here is the script that seems to be working:

;Install the SOCO Ribbon
Run("I:\Public\Applications\SOCO Ribbon\setup.exe")

For $i = 1 To 3000 ;tries for about 15 to 20 minutes and then leaves the loop
    Sleep(1200)
    If WinExists("InsertCompanyAddInSetup", "repair or remove") Then
        WinClose("InsertCompanyAddInSetup", "repair or remove")
        Exit ;exits the entire script
    EndIf

    If WinExists("InsertCompanyAddInSetup", "through the steps") Then
        WinActivate("InsertCompanyAddInSetup", "through the steps")
        WinWaitActive("InsertCompanyAddInSetup", "through the steps")
        Send("!n")
        WinWaitActive("InsertCompanyAddInSetup", "Select Installation Folder")
        Send("!n")
        WinWaitActive("InsertCompanyAddInSetup", "Confirm Installation")
        Send("!n")
        WinWaitActive("InsertCompanyAddInSetup", "Installation Complete")
        WinClose("InsertCompanyAddInSetup", "Installation Complete")
        WinWaitClose("InsertCompanyAddInSetup", "Installation Complete")

        DirCopy("I:\Public\Applications\SOCO Ribbon\SOCO Templates", "C:\Documents and Settings\All Users\Templates\SOCO Templates", 1)
        Exit ;exits the entire script
    EndIf
Next

Thank you very much GEOSoft, herewasplato, and junkew!


www.stonge.com

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
Sign in to follow this  

×