Jump to content

need help with if...then...else statement


Recommended Posts

Hi, i am new to AutoIT and i am trying to write a script which will start java install and if java is installed then it should launch with the browser else it should start the installation. I am not getting what wrong i am doing...i am stuck...please help

 Run("c:\Temp\jdk-7u45-windows-x64.exe")
   if WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit)", "reinstall it?") Then
   send("!n")
   Else
   WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit) - Setup", "Welcome to the Installation")
   Send("!n")
   WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit) - Custom Setup")
   Send("!n")
   WinWaitActive("Java Setup - Destination Folder", "Install to")
   send("!n")
   WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit) - Complete")
  
   EndIf
   ; Java installation complete
   Send("{ENTER}")

   ; Make default plage blank
   ShellExecute("C:\Program Files\Internet Explorer\iexplore.exe", "about:blank")

 

Link to comment
Share on other sites

  • Developers

You are waiting for this window so the script will stop there until this window appears.

WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit)", "reinstall it?")

This is probably not the best approach but should demonstrate where you were going wrong: (UnTested)

Run("c:\Temp\jdk-7u45-windows-x64.exe")
While 1
    If WinExists("Java SE Development Kit 7 Update 45 (64-bit)", "reinstall it?") _
    or WinExists("Java SE Development Kit 7 Update 45 (64-bit) - Setup", "Welcome to the Installation") Then
        ExitLoop
    EndIf
    Sleep(100)
WEnd

If WinExists("Java SE Development Kit 7 Update 45 (64-bit)", "reinstall it?") Then
    Send("!n")
Else
    Send("!n")
    WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit) - Custom Setup")
    Send("!n")
    WinWaitActive("Java Setup - Destination Folder", "Install to")
    Send("!n")
    WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit) - Complete")

EndIf
; Java installation complete
Send("{ENTER}")

; Make default plage blank
ShellExecute("C:\Program Files\Internet Explorer\iexplore.exe", "about:blank")

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

Thanks a lot Jos for your reply. however i am not waiting for that window. Below is the situation:

if WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit)", "reinstall it?") Then
      send("!n")

if this is true then it opens browser and this is expected behavior.

However if the java is not installed it comes to this window and is not sending the "!n"

WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit) - Setup", "Welcome to the Installation")

Send("!n")

 

 

i will also try your way and see how it goes

 

 

Link to comment
Share on other sites

  • Developers

Maybe you need to wait a little for the Window to complete displaying before sending the "!n" and ensure the Window hasn't lost focus.
You could do a WinActivate() to regain focus in case it lost it.

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

  • Developers

Again ... as stated in my first post: Your logic is flawed as your script will get stuck on the first WinWaiActive() until that is true!
That is why I posed the script in my reply to show you how you could work around that .. (Untested so can't promise it works with the installer you use)\

Add this statement at the top of your script so you can see on which line your script hangs:

Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info

.. and hover over the trayicon when it hangs.

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

thanks Jos, i understand the flaw in my code and tried to follow the code you gave, when i try to run it it says that:

"If" statements must have a "Then" keyword.:
if WinExists("Java SE Development Kit 7 Update 45 (64-bit)", "reinstall it?")

then i corrected to:

 if WinExists("Java SE Development Kit 7 Update 45 (64-bit)", "reinstall it?") Then

or WinExists()

 

but still same issue, when i hover over tray icon it says Sleep(100)

please help

 

Capture.JPG

Capture.JPG

Link to comment
Share on other sites

  • Developers

You need to copy & paste everything! ;)

There is an underscore at the end of the If line

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

  • Developers

So normally when I really would need to do WinExists() & Send() depending on multiple possibilities I would do a loop like this in stead of what i posted earlier, but that was an effort to show your logic flaw:

 

Run("c:\Temp\jdk-7u45-windows-x64.exe")
While 1
    If WinExists("Java SE Development Kit 7 Update 45 (64-bit)", "reinstall it?") Then
        Send("!n")
        ExitLoop
    EndIf
    If WinExists("Java SE Development Kit 7 Update 45 (64-bit) - Setup", "Welcome to the Installation") Then
        Send("!n")
        WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit) - Custom Setup")
        Send("!n")
        WinWaitActive("Java Setup - Destination Folder", "Install to")
        Send("!n")
        WinWaitActive("Java SE Development Kit 7 Update 45 (64-bit) - Complete")
        ExitLoop
    EndIf
    Sleep(100)
WEnd

; Java installation complete
Send("{ENTER}")

; Make default plage blank
ShellExecute("C:\Program Files\Internet Explorer\iexplore.exe", "about:blank")

In this way you can add as many Window options and their actions as you want. :)
P.S. I would prefer using ControlSend() when possible!

Jos

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

Just a heads-up... You'll have to change this code every time you want to implement a new update of a new version of java. You may want to change those titles to just look for the beginning of that string, so it is slightly more prepared for the future.

Another thing you may want to consider is installing java directly (without installer), by simply placing the required files in a directory of your choice and setting the JAVA_HOME/PATH. That way you don't have to worry about installers at all.

Just my $0.02.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Thanks Sadbunny :)

I am again stuck and not understanding what wrong i am doing in this. After WEnd, security information popup comes up and it should send !r but its not doing anything. when i hover in the task bar icon it says paused at sleep(100)....Please help

 

Capture.JPG

Link to comment
Share on other sites

  • Developers

Just an FYI: No need to post Captures of your code, but simply copy&paste in in the Window you get when pressing <> in the tool bar of the editor.

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

  • 2 weeks later...

Thanks Jos

Need one more help. I have a batch file where user select his location and depending on his location software installation starts from that server. i want that input from the user of his location to be the input to my autoit program...how to do that?

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