2

I am working in a External HDD manufacturing company. I have requirement to upgrade the FW for thousands of HDDs. I have to upload two files in sequence to get the upload completed. To do manual processing takes time as well as allows chance of Human error. So I decided to automate the key strokes and mouse clicks using Auto Hot Key. I have also compiled the script. However the script is unstable. Sometimes it works fine. Some times the control click don't work. Sometimes the key input won't be typed full. But the script is OK based on my knowledge. If there is any mistake please correct me. Also I want to safe remove the drive so if there is any coding for it please add it up as well

My process is explanation is as below.

  1. Connect the HDD to PC and Wait PC to Detect HDD
  2. Open the FW upload tool
  3. Click RESCAN and wait for HDD to show up in the tool
  4. Click browse for first FW file.
  5. Then select the check box near HDD shown in the tool.
  6. Click DOWNLOAD and press enter at next warning message.
  7. Wait for Download to finish and press OK after success message shown.
  8. Repeat step 3 to 7 for second FW file.
  9. Click exit and Safe remove the HDD.

Below is my script.

Run, open "Application Location"
Winwait, Warning
if ErrorLevel
{
    MsgBox, Window timed out.
    return
}
else
{
ControlClick, OK, Warning
Winwait, Application Window name
if ErrorLevel
{
    MsgBox, WinWait timed out.
    return
}
else
{
; Upload first FW File
ControlClick, Rescan, Application Window name
ControlClick, Browse, Application Window name
Winwait, Open
if ErrorLevel
{
    MsgBox, WinWait timed out.
    return
}
else
{
SendInput, {Raw}Location of First File
Send, {Enter}
}
sleep, 1500
WinActivate, Application Window name
CoordMode, Mouse, Relative
Click 43, 126
ControlClick, Download, Application Window name
Winwait, Warning
if ErrorLevel
{
    MsgBox, WinWait timed out.
    return
}
else
{
Send, {Enter}
}
Winwait, Download Successful
if ErrorLevel
{
    MsgBox, WinWait timed out.
    return
}
else
{
ControlClick, OK, Download Successful
}
}
; Upload Second FW File
WinActivate, Application Window name
ControlClick, Rescan, Application Window name
ControlClick, Browse, Application Window name
Winwait, Open
if ErrorLevel
{
    MsgBox, WinWait timed out.
    return
}
else
{
SendInput, {Raw}Second FW File location
Send, {Enter}
}
sleep, 1500
WinActivate, Application Window name
CoordMode, Mouse, Relative
Click 43, 126
sleep, 2000
ControlClick, Download, Application Window name
Winwait, Warning
if ErrorLevel
{
    MsgBox, WinWait timed out.
    return
}
else
{
Send, {Enter}
}
Winwait, Download Successful
if ErrorLevel
{
    MsgBox, WinWait timed out.
    return
}
else
{
ControlClick, OK, Download Successful
sleep, 1500
ControlClick, Exit, Application Window name
}
}
5
  • 1
    Don't rely on advice from people on the Internet to accomplish such a very important task for reliability and usability of peoples' HDDs. Get someone to actually develop and test some software for you to do this automatically! Commented Sep 23, 2015 at 3:43
  • erm. No, AHK is entirely on topic here. In addition to what @allquixotic said, its pretty difficult to test an answer without knowing the software you use, and if there's other bottlenecks
    – Journeyman Geek
    Commented Sep 23, 2015 at 3:44
  • Also, perhaps more importantly, automating the Windows GUI is always going to be inherently buggy by design, due to race conditions, synchronization, input lag, etc. Instead, get access to the source code of the firmware patching tool, and write a non-interactive (console based) version of it that you can automate with command-line flags or a config file, and have it automatically wait for an HDD then automatically flash the firmware if applicable. This task requires a much more robustly engineered solution than you seem to be attempting here. Commented Sep 23, 2015 at 3:44
  • Thanks for your comments guys. Let me get it clear and correct me if I am wrong. You guys are saying that the instability is not from my script but from the natural behavior of Windows GUI that occurs from automation, right? And another thing is the firmware patching tool is a third party tool and I cannot get to see or modify its source code. This tool is provided by the client who wants us to upgrade the firmware and I have discussed with them to automate the process but they denied it already. That's why I was trying other option and found AHK.
    – Dragonborn
    Commented Sep 23, 2015 at 4:42
  • @Dragonborn - Honestly, what you describe, is the natural behavior of almost any modern OS GUI. A office mate describe putting a recent version of Ubuntu on a PC that was more then 10 years old, what he describes is having to wait on the mouse to move, modern OS are both faster and more resource intensive at the same time. The point as our electronics become faster they are have the capability to do more, this means some very basic concepts surrounding UIs, get more complex as time goes on. Any programming source can be purchased for the right price.
    – Ramhound
    Commented Sep 23, 2015 at 11:45

1 Answer 1

2

A few thoughts:

  1. If you return on error level in the first few lines, no need to encapsulate the rest of the script in an Else statement and encapsulating brackets. Not needed.

  2. The use of WinWait is not the same as WinWaitActive. A window can exist without being active, so always use WinWaitActive unless you need to look for a window in the background. Using WinWait can cause your script execution to continue past the wait statement before the window is actually active, causing some of the problems you're describing.

  3. Unless there is a need to switch between Send and SendInput, stick to one or the other... usually SendInput is the more preferable option for reasons explained in the help files. Using both of them (depending on the program being used) can cause timing issues as to how the keys get sent.

  4. Use WinWaitActive after any instances of WinActivate to make sure the window is active before continuing.

  5. For code that gets repeated, try using a subroutine, i.e., gosub or function call. Since the file location gets changed you could set the file location with a variable between calls, or use the variable as a parameter of the function call. This would keep you from having to re-write everything twice if you change the routine.

2
  • Thanks for your suggestion. Let me re-write my script and check for the solution.
    – Dragonborn
    Commented Sep 23, 2015 at 4:48
  • Another helpful tool should you need it is to insert sleep statements, so if the script is doing something too quickly for windows you can try inserting a nominal sleep statement of several hundred milliseconds. Inserting a much longer sleep statement (i.e., a few seconds), can also help pinpoint issues. Liberal use of the tooltip command is also helpful for understanding where the program is executing at when you're watching it running.
    – JJohnston2
    Commented Sep 23, 2015 at 4:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .