Automate a program removal

This script shows how to automate the dialog box Add/remove Programs, for instance under Windows XP.

 

'Don't use Windows menu Start, but call directly Control Panel

'with the parameter for calling Add/Remove screen

Shell("control.exe"+" appwiz.cpl",1)

 

'Insert a synchronization on window Add/remove programs to be sure it has enough time to load.

'As the window is displayed before all the programs are listed within the window, a simple Synchronization on Window does not work.

'It needs to wait until Change/Remove button is really displayed within the Add or Remove Programs window.

'For waiting that text, we use a Pause on OCR Text (not available in WinTask Lite).

Pause until

  TextOCR("Remove")

  InWindow("RUNDLL32.EXE|DirectUIHWND|Add or Remove Programs|1",1)

  InArea(603,120,15,79)

PauseFalse

  MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")

  End

EndPause

 

'Add a small pause to leave some time for the other programs to be displayed.

Pause 2

 

'Press Down key as many times as needed to select the Program to remove.

UseWindow("RUNDLL32.EXE|DirectUIHWND|Add or Remove Programs|1",1)

  SendKeys("<Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Down>",NoActivate)

  pause 50 ticks

 

'We use a ClickOnTextOCR to click the Remove button for the selected Program
'The InArea coordinates can be different on your PC, you can re-generate the couple of lines
'below using ClickOnTextOCR wizard.
ret = UseOCREngine(2)
UseWindow("RUNDLL32.EXE|DirectUIHWND|Add or Remove Programs|1",1)
ClickOnTextOCR("Remove", left, single, InArea(642, 461, 43, 14))


'Click Yes button when the Uninstall confirmation window is there.
'Change the window name accordingly to your software uninstallation window.
UseWindow("_IU14D2N.TMP|#32770|Compare It! Uninstall",1)
 Click(Button,"&Yes")


'Selected program uninstallation launched - put here the uninstall process automation lines
UseWindow("_IU14D2N.TMP|#32770|Uninstall",1)
Click(Button,"&Yes")

 
'Close Add/remove programs

CloseWindow("RUNDLL32.EXE|NativeHWNDHost|Add or Remove Programs",1)