Sign in to follow this  
Followers 0
kzar

Good example of installer automation script?

10 posts in this topic

Hi I was wondering if there is a clean reliable example script that steps through an program's installer? Here are the ways I have been writing the scripts so far..

To start with I was using winwaitactive() and send() like this:

; Run the installer and wait for it to load
Run("En_UK\Setup.exe")

; Step through the setup
; Welcome
WinWaitActive("Setting up Olympus DSS Player Version7","Welcome to the InstallShield Wizard for Olympus DSS Player Version7")
Send("!n")

; License
WinWaitActive("Setting up Olympus DSS Player Version7","License Agreement")
Send("!y")

; Serial
WinWaitActive("Setting up Olympus DSS Player Version7","Customer Information")
Send("{TAB}{TAB}" & $serial & "!n")

But as I have had problems with reliablity I have been using lod3n's example of looping a select statement of all the different possible windows like this:

run("installer.exe")
  while 1
   sleep(100)
  select
    case WinExists("Confirmation","Are you sure")
       ControlClick("Confirmation","Are you sure","Button2")
       While WinExists("Confirmation","Are you sure")
           sleep(100)
       wend
    case WinExists("Installation Complete","Installation completed succ")
        ControlClick("Installation Complete","Installation completed succ","Button1")
        While WinExists("Installation Complete","Installation completed succ")
           sleep(100)
       wend
       exitloop
   endselect
wend
exit

Problem is though theres a lot of duplicated code doing it like that so I tried to write a function to neaten it up, without a lot of luck but here it is:

; This If statement would be a case in a select inside a loop normaly
If WinExists("Example window", "Welcome to the example program blah blah") Then
  HandleWin("Confirmation","Are you sure", 
          "Example window", "Welcome to the example program blah blah",
          "MsgBox(0, 'Huray', 'it worked!')
           MsgBox(0, 'Huray', 'And this!')")
EndIf

Func HandleWin($title, $text, $commands)
; Split up the commands and count
     $command = StringSplit($commands, '\n', 1)
     $commandCount = UBound($command)

; Loop through commands and execute them
     For $i = 0 to $commandCount Step +1
         Execute($command[$i])
     Next

; Wait for window to close
     While WinExists($title,$text)
           sleep(100)
     wend
     Return $value
EndFunc

So if anyone has a good clean example or some tips it would be appreciated, thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Well my standard would be..

If you know only one thing can happen next. then I use

Beware I got the functions at home, but not here so this is from what I can recal of them :shocked:

Function License()
     $title = "Window text"
     $text = "Window text"
     WinWait($title, $text)
     WinActivate($title, $text)
     WinWaitActive($title, $text)
     Then Do the changes you need
     ControlClick($title,$text,"Button1") ; Here is button1 an example
EndFuncoÝ÷ Ø梷­©èì"Ú0q©ì-éȺÇ)jëh×6Function WinLoop($a_Array)
     $looping = true
     While $looping
          For $i = 0 To UBound($a_Array) - 1
               If WinExists($a_Array[$i][0], $a_Array[$i][1]) Then
                    $looping = Call($a_Array[$i][2])
                    If NOT($looping) Then ExitLoop
               EndIf
          Next
          Sleep(100)
     WEnd
EndFunc
Edited by Shevilie

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

That looks good Shevillie, thanks. Only problem I can see is what if I wanted to do more than one command if a window exists?

Share this post


Link to post
Share on other sites

The Call refer to the function that should be run... The a_Array[x][3] contains the function name of the function to run... this should return true or false... true if you want the loop to continue.. false if you want the loop to exit :shocked:


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

Ah, well, I didn't mean for you to copy and paste. This one is a little more production ready:

$pid = Run("installer.exe")
While ProcessExists($pid)
    Sleep(100)
    _installerClickButton("Confirmation", "Are you sure", "Button2")
    _installerClickButton("Installation Complete", "Installation completed succ", "Button1")
WEnd

Func _installerClickButton($title, $string, $button)
    If WinExists($title, $string) Then
        ControlClick($title, $string, $button)
        While WinExists($title, $string)
            Sleep(100)
        WEnd
    EndIf
EndFunc


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

The Call refer to the function that should be run... The a_Array[x][3] contains the function name of the function to run... this should return true or false... true if you want the loop to continue.. false if you want the loop to exit :shocked:

Yea I understood that, but what if the you want to run more than one function? a_Array[x][3] can only contain one function surely?

Ah, well, I didn't mean for you to copy and paste. This one is a little more production ready:

Thanks that looks good too but I still can't figure out a general way to handle more than one command?

I suppose the main things I need to do are to click buttons and enter text so I could maybe have the last parameter being an array of commands somthing like this:

$array[0] = "click, Button2"
$array[1] = "text, TextBox1, Hello"
_installerHandleWindow("Enter serial", "Please enter serial number", $array)

Hmm not the cleanest way to do it though.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Well this is totaly un-tested (will have to wait till I get to work tommorow as I run linux) and I am quite tired but here is what I have so far :shocked:

$pid = Run("installer.exe")
While ProcessExists($pid)
    Sleep(100)
        
    $command[0] = "click, Button2"
    $command[1] = "wait"
    _installerHandleWindow("Confirmation", "Are you sure", $command)

    $command[0] = "click, Button1"
    $command[1] = "wait"
    _installerHandleWindow("Installation Complete", "Installation completed succ", $command)

    $command[0] = "text, TextBox1, Hello"
    $command[1] = "click, Button2"
    $command[2] = "wait"
    _installerHandleWindow("Enter serial", "Please enter serial number", $command)
WEnd

Func _installerHandleWindow($title, $text, $commands)
If WinExists($title, $text) Then
    For $i = 0 to UBound($commands) Step +1
        $commands[i] = StringStripWS($commands[i], 8)
        $command = StringSplit($commands[i], ',', 1)
        switch StringLower($command[0])
            case "click"
                ControlClick($title, $text, $command[1])
                
            case "text"
                ControlSetText($title, $text, $command[1], $command[2])

            case "wait"
                While WinExists($title,$text)
                    sleep(100)
                wend
        EndSwitch
    Next
EndIf
EndFunc

I do realize (as I type this) that there is a problem with the $command array constantly being changed in the loop which isn't very good and possibly could mess up if it isn't cleaned up in between each use.

Anyway thanks for the help so far and I will post a sorted out version when I get the chance to fix it all up.

Edited by kzar

Share this post


Link to post
Share on other sites

Yea I understood that, but what if the you want to run more than one function? a_Array[x][3] can only contain one function surely?

Thanks that looks good too but I still can't figure out a general way to handle more than one command?

The function you Call will contain all the functions code etc for that step...

So if the function you call is License.. Then the License would look like this

Func License()
    LicensePartOne ;Function 1 you need
    LicensePartTwo ;Function 2 you need
    Send("fhkjdlhsflk")
    Return True
EndFunc

So you can have all the functions you would like gathered in the one you call :shocked:


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

Heres what I have so far, the handlewindow function is pretty much there.

I am going to add a function to create sections because sometimes you have to have seperate lumps of windows that are each finished by a different window like one for the installer and one for the setup. Also I am gona make a generic fuction to loop through those chunks of windows :shocked:

Its getting there anyway, hopefully when I have done the other 2 functions it will be down to one line to add each window and then one line to loop through those windows.

$command[2] = ["click, Button2","wait"]
_installerHandleWindow("Confirmation", "Are you sure", $command)

$command[2] = ["click, Button1","wait"]
_installerHandleWindow("Installation Complete", "Installation completed succ", $command)

$command[3] = ["text, TextBox1, Hello","click, Button1","wait"]
_installerHandleWindow("Enter serial", "Please enter serial number", $command)


Func _installerHandleWindow($title, $text, $commands)
If WinExists($title, $text) Then
    For $i = 0 to UBound($commands) -1  Step +1
        $commands[$i] = StringStripWS($commands[$i], 8)
        $command = StringSplit($commands[$i], ',', 1)

        switch StringLower($command[1])
            case "click"
                ControlClick($title, $text, $command[2])

            case "text"
                ControlSetText($title, $text, $command[2], $command[3])

            case "wait"
                While WinExists($title,$text)
                    sleep(100)
                wend

            case "close"
                winclose($title, $text)

            case "exitloop"
                return 1
        EndSwitch
    Next

return 0
EndIf
EndFunc

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

OK here we go, just got this finished. It seems to work alright but I haven't had chance to check it over or test very thoroughly so there may be bugs. Anyway its quite nice now because theres no repetition and its only one line per window:

DIM $windows[1][3]

Run("installer.exe")

_addWindow("Confirmation", "Are you sure", "click, Button2 | wait")
_addWindow("Enter serial", "Please enter serial number", "text, TextBox1, Hello | click, Button2 | wait")
_addWindow("Installation Complete", "Installation completed succ", "click, Button1 | wait | exitloop")
_loopWindows()

Func _addWindow($title, $text, $command)
    $windows[UBound($windows) - 1][0] = $title
    $windows[UBound($windows) - 1][1] = $text
    $windows[UBound($windows) - 1][2] = $command
    
    REDIM $windows[Ubound($windows) +1][3]
EndFunc

Func _loopWindows()
    While 1
        For $i = 0 to Ubound($windows) - 1 Step +1
            If _installerHandleWindow($windows[$i][0], $windows[$i][1], $windows[$i][2]) == 1 Then
                REDIM $windows[1][3]
                ExitLoop 2
            EndIf
        Next
    WEnd
EndFunc

Func _installerHandleWindow($title, $text, $commands)
If WinExists($title, $text) Then
    $commands = StringStripWS($commands, 8)
    $command_array = StringSplit($commands, '|', 1)

    For $i = 1 to UBound($command_array) -1  Step +1
        $command = StringSplit($command_array[$i], ',', 1)

        switch StringLower($command[1])
            case "click"
                ControlClick($title, $text, $command[2])

            case "text"
                ControlSetText($title, $text, $command[2], $command[3])

            case "wait"
                While WinExists($title,$text)
                    sleep(100)
                wend

            case "close"
                winclose($title, $text)

            case "exitloop"
                return 1
        EndSwitch
    Next

return 0
EndIf
EndFunc
Edited by kzar

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  
Followers 0