Automate a software installation

The following script installs Acrobat under XP ; two functions are defined for testing if the button we want to click is ready for being clicked ; GetWindowHandle and UseWindowHandle are used (instead of UseWindow) as Acrobat window names vary from one installation to another.

The two functions, wait_focus and wait_top, can be used on any Windows versions.

If you want that at the end of a first installation script, the script reboots and at reboot, a second script is started, include at the end of the first script a line writing in Registry the launch of second script (using the command line for running a script), then the WinTask statement Reboot. So at reboot, the second script will be started and in the second script, you can delete the Registry entry which launches the script.

You can find the corresponding script file under Script_Examples, sub-directory of scripts.

 

'Function waits for object objet$ to have focus for Tmax seconds

function wait_focus(objet$,Tmax)

local i, exitr, a$

 

i=0

exitr=0

 

repeat

a$=focus$()

if instr(a$,objet$)=0 then

pause 1

i=i+1

if i > Tmax then

msgbox("wait too long for "+objet$)

stop

endif

else

exitr=1

endif

until exitr=1

endfunction

'--------------------------------------------

'Function waits for object objet$ to be on top for Tmax seconds

function wait_top(objet$,Tmax)

local i, exitr, a$

 

i=0

exitr=0

 

repeat

a$=top$()

if instr(a$,objet$)=0 then

pause 1

i=i+1

if i > Tmax then

msgbox("wait too long for "+objet$)

stop

endif

else

exitr=1

endif

until exitr=1

endfunction

'-----------------------------------------------

 

#ActionTimeout=10

 

'Start Acrobat setup from CDROM

Shell("f:\Acrobat7\Setup.exe",1)

 

'License window

wait_focus("License",10)

a=getwindowhandle(top$())

usewindowhandle(a)

Click(Button,"&Accept")

 

'Installation choice

wait_focus("Button|Typical",10)

a=getwindowhandle(top$())

usewindowhandle(a)

Click(Button,"&Next >")

 

'User information window

wait_top("User information",10)

a=getwindowhandle(top$())

usewindowhandle(a)

Click(Button,"&Next >")

 

'Confirmation window

wait_focus("Button|&Yes",10)

a=getwindowhandle(top$())

usewindowhandle(a)

Click(Button,"&Yes")

 

'Last validation

wait_focus("Button|&Next",10)

a=getwindowhandle(top$())

usewindowhandle(a)

Click(Button,"&Next >")