ved230609

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

17 posts in this topic

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

 

Share this post


Link to post
Share on other sites



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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

 

 

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

i tried using sleep(2000) and then WinActivate() didn't help. I also tried the code that you gave previously but still same issue. Please help

Capture.JPG

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

You need to copy & paste everything! ;)

There is an underscore at the end of the If line

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Java is really easy to silent install, I usually use the .MSI files and set them up to turn off all the auto update junk.

 

For the .exe just a /s should do the silent install.

 

Share this post


Link to post
Share on other sites

thank a lot Jos, i finally got this working...

@ViciousXUSMC, i would do that but i have to push this to 1000 users. Java install is just a start there are further more operations after this.

 

Thanks a ton Jos

 

Capture.JPG

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

great thanks again Jos....your help very much appreciated

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thank you guys, i figured it out.....Thanks again for all your help

Share this post


Link to post
Share on other sites

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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?

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