Jump to content

Requesting help with conditional statements


Recommended Posts

Hello:

I'm looking for assistance with an AutoIt script that I'm working on. I need to apply a firmware update on a number of SSDs. A percentage of the drives already have the latest version. Trying to use AutoIt to automate the install so that drives that need the firmware get it while those that don't are not patched.

Here is my script:

Run("Firmware_Update.exe")

Sleep (5000)

If WinWaitActive("Nothing To Update", "There are no SSDs on your system that need to be updated.") Then

Send("{ENTER}")

Else

WinWaitActive("Crucial SSD Firmware Update Utility", "This program will update the firmware on your Crucial SSD.")

Send("{TAB}{ENTER}")

WinWaitActive("Crucial SSD Firmware Update Utility", "PLEASE READ THIS LICENSE AGREEMENT")

Send("{TAB}{TAB}{ENTER}")

WinWaitActive("Crucial SSD Firmware Update Utility", "This program will update the firmware on your Crucial SSD.")

Send("{TAB}{TAB}{ENTER}")

EndIf

On systems that have the latest firmware this script allows the update program to simply close. That is great. However, on systems that need the update this script simply stalls on the first screen. (Attachted: instead of selecting the "License" button the program just sits there.). If I run the code within the "Else... EndIf" clause as a separate script then the update works fine. Clearly, I have not written the first conditional properly. Would be grateful for any assistance. Thanks a lot.

post-76120-0-99087200-1362592867_thumb.p

Link to comment
Share on other sites

I would use

If WinExists("Nothing To Update", "There are no SSDs on your system that need to be updated.") Then

instead because you are just checking to see which window is there.

Personally, I would put it in a loop with a timer (just in case it takes longer than 5 seconds)

something like

Run("Firmware_Update.exe")
$timer = TimerInit()
Do
 If WinExists("Nothing To Update", "There are no SSDs on your system that need to be updated.") Then
  Send("{ENTER}")
  ExitLoop
 ElseIf WinExists("Crucial SSD Firmware Update Utility", "This program will update the firmware on your Crucial SSD.") Then
  Send("{TAB}{ENTER}")
  WinWaitActive("Crucial SSD Firmware Update Utility", "PLEASE READ THIS LICENSE AGREEMENT")
  Send("{TAB}{TAB}{ENTER}")
  WinWaitActive("Crucial SSD Firmware Update Utility", "This program will update the firmware on your Crucial SSD.")
  Send("{TAB}{TAB}{ENTER}")
  ExitLoop
 EndIf
Until TimerDiff($timer) > 10000; it should run this loop for 10 seconds if neither window has appeared, after which it will exit

You might have better luck with controlclick and controlsend if you use the autoit window info tool to get the buttons class|instance info. Then you would have to use send enter and tabs

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Thanks for the reply, kaotkbliss.

I tried your modified script. Now I'm able to update systems that need the firmware but the script pauses when run on a system that is already patched. One step forward and one step back. =P I'll keep tinkering. If anyone else has ideas I'm all ears. Thanks.

Link to comment
Share on other sites

You are performing actions without verifying that the state's of the window and control are ready to accept actions (maybe the button is inactive; maybe the window is visible, but not active yet). Also, sends are flakey, since sometimes applications cannot consume the sends as quick as the default Autoit send/senddelay is set for (5ms).

Look into wingetstate, controlcommand (isvisible|isenabled), and controlsend/controlclick.

edit: the window state is fine, since you are waiting for it to be active...might want to loop for it to exist instead, incase issues occur in the installer...else you will hang the script if the window never comes up and/or never becomes active (or add the timeout param into winwaitactive)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Perhaps the Enter/Ok/Exit button (whatever it's called) is not active and therefore, when the "Enter" is sent, it's not recieved by the button. Use the window info tool that came with autoit and see if you can get a class name and instance of the button to use controlclick (or controlsend) instead. That will send the command dirrectly to the button whether it's selected/active or not.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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