How to automatically install/uninstall software without human interaction

July 11, 2011 by
Filed under: automation, test 

Sometimes we need to automatically install/uninstall software without human interaction, especially for system performance test. How can we make it work?

A simple and easy way is to leverage AutoIt. Auto it can be used to simulate keystrokes and mouse movements automatically. Just download it from here. Then install it.

And open an editor, SciteEditor4AutoIt3 is recommended as a bundle in AutoIt, write autoit script by examples provided by AutoIt help document. During the writing, you can use AutoIt Window Info which is installed with AutoItV3 to capture your software window information. You will need these window information in your scripts.

Here’s the script for automatically install iTunes 9.0:

; filename: install.itunes.au3,  automatic software install
run("iTunesSetup-9.0.2.25.exe")
WinWaitActive( "iTunes + QuickTime" )

; click next
ControlClick("iTunes + QuickTime", "", "[ID:6315]")
WinWaitActive( "iTunes + QuickTime" )

; accept license
ControlClick("iTunes + QuickTime", "", "[ID:6434]")
WinWaitActive( "iTunes + QuickTime" )

;; click next
ControlClick("iTunes + QuickTime", "", "[ID:6315]")
WinWaitActive( "iTunes + QuickTime" )

;;click install
ControlClick("iTunes + QuickTime", "&Install", "[ID:6348]")

;; wait the install successful UI:
While 1
	; find control (Yes button) whose Text is &Finish :
	$var = ControlGetText("iTunes + QuickTime", "", "[Text:&Finish]") 

    If $var == "&Finish" Then
		; tick not to open UI
		ControlClick("iTunes + QuickTime", "", "[ID:6414]")

		; send Alt + F to finish install
		Send("!F")

        ExitLoop
    EndIf

	Sleep(1000)
WEnd

Here’s the script for uninstall iTunes 9.0:

; automatic software install
run("iTunesSetup-9.0.2.25.exe")
WinWaitActive( "iTunes + QuickTime" )

; click remove
ControlClick("iTunes + QuickTime", "&Remove", "[ID:6484]")

; find "Yes" button until it show, and then send Alt + Y
While 1
	; find control (Yes button) whose ID is 6434 :
	$var = ControlGetText("iTunes + QuickTime", "", "[ID:6434]") 

    If $var == "&Yes" Then
		; send Alt + Y to confirm uninstall
		Send("!Y")

        ExitLoop
    EndIf

	Sleep(1000)
WEnd

; find "Finish" button until it show, and then send Alt + F
While 1
	; find control (Yes button) whose ID is 6434 :
	;$var = ControlGetText("iTunes + QuickTime", "", "[ID:6412]")
	$var = ControlGetText("iTunes + QuickTime", "", "[Text:&Finish]") 

    If $var == "&Finish" Then
		; send Alt + F to finish uninstall
		Send("!F")
		;ControlClick("iTunes + QuickTime", "&Finish", "[ID:6412]")

        ExitLoop
    EndIf

	Sleep(1000)
WEnd

sleep(500);

;WinWaitActive( "iTunes + QuickTime" ) ; commented by david, 2010/05/04
; click "No" to not reboot the os:
ControlClick("iTunes + QuickTime", "&No", "[ID:7]")

;MsgBox(4096, $count,"", 5);

The script for install Microsoft Office 2007:

; filename: install.office.au3 ,automatic software install
run("office2007\\setup.exe")

WinWaitActive( "Microsoft Office Professional 2007" )
Sleep(100)
;ControlClick("Microsoft Office Professional 2007", "", "[Text:Continue]")
Send("!c")

WinWaitActive( "Setup" )

ControlClick("Setup", "", "[Text:&No]")

WinWaitClose("Setup")

; Alt + a to accept the terms of this agreement:
Send("!a")
Sleep(100)

; click "continue" button:
Send("{ENTER}");

; Click "Install Now"
Send("!i")

Sleep(500)

;WinWaitClose( "Microsoft Office Professional 2007" )
;WinWaitActive( "Microsoft Office Professional 2007" )

While 1
	; Send Alt + C to "Close":
   Send("!c")

	; find control (Yes button) by Text :
	$text = WinExists ("Microsoft Office Professional 2007", "")

    If $text == 0 Then
	     ;; window not found
         ExitLoop
    EndIf

	Sleep(1000)
WEnd

 

The script for uninstall Microsoft Office 2007:

; automatic software uninstall
run("office2007\\setup.exe")

WinWaitActive( "Microsoft Office Professional 2007" )

; remove:
Send("!m")

; Send Enter to "continue" :
Send("{ENTER}");

; confirm the dialog of "Are you sure you want to remove Microsoft Office professional 2007?":
WinWaitActive( "Setup" )
ControlClick("Setup", "", "[Text:&Yes]")
WinWaitClose("Setup")

While 1
   ; try to Send Alt + C to "Close":
   Send("!c")
   Sleep(100)

	; find control (Yes button) by Text :
	$var = ControlGetText("Setup", "", "[Text:&No]") 

    If $var == "&No" Then
		 ;;WinWaitActive( "Setup" )
		 ControlClick("Setup", "", "[Text:&No]")
		 WinWaitClose("Setup")
         ExitLoop
    EndIf

	Sleep(500)
WEnd
Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Comments

One Comment on How to automatically install/uninstall software without human interaction

  1. Mayson on Wed, 12th Sep 2012 10:12 pm
  2. Tried the uninstall script which does not do anything. What needs to be changed from my side?