Forum Discussion

srikanth2801's avatar
srikanth2801
Contributor
14 years ago

How to Uninstall application fro add remove programs.

Hi all,



i want to write a script which it should uninstall the application from the add remove programs.

i know the name of the application.



using that can we able to click on uninstall to uninstall the application.



thanks in advance.

15 Replies

  • tandurq_1's avatar
    tandurq_1
    New Contributor
    Had to do a bit of conversion in VBscript on Win7 but this seems to work.





    Sub SelectApplicationFromControlPanel()


      Dim WshShell, oExec, p, w, applicationWnd


      Dim button, applicationName, buttonName, programsList


     


      applicationName = "APPLICATION_NAME"


      buttonName = "Uninstall*"


      


       Set WshShell = CreateObject("WScript.Shell")


      Set oExec = WshShell.Exec("RunDll32.exe shell32.dll,"&_


                                "Control_RunDLL appwiz.cpl,,0")  


      BuiltIn.Delay(10000)


      Sys.Process("Explorer").Refresh()


      Set p = Sys.Process("Explorer").FindChild("WndCaption", "Control Panel\Programs\Programs and Features")


      If Not p.Exists Then


        Call Log.Error("The 'Add or remove programs' dialog was not found")


      Else


        Set programsList = p.FindChild("WndClass", "SysListView32", 20) 


        Log.Message(p.FullName)


        Call programsList.ClickItem(applicationName, 0)


        Dim propArray(1)


        propArray(0) = "Caption"


        propArray(1) = "ObjectType"


        Dim valuesArray(1)


        valuesArray(0) = buttonName


        valuesArray(1) = "Button"


        Set button = p.FindChild(propArray, valuesArray, 20)


        Call button.Click()




        'Insert Uninstall Code Here



        p.Close()


      End If


    End Sub
  • I tried to use Allen's script to uninstall my application on Windows 7.  I would like to know how can I know the uninstall process is finished?  I want to wait for uninstall process to finish then close "Programs and Features" window.  I tried to use the following code to detect the uninstall process:



    var AW = Sys.Desktop.ActiveWindow();

    while(aqString.Find(AW.WndCaption, "my product name") == -1)

    {

      AW = Sys.Desktop.ActiveWindow();  <= endless loop

    }



    but above code ran forever in TestExecut but it works in TestComplete.  What is the best way to get uninstall process?  I'm using MSI installer to install my application.



    Thank you in advance.

    Puyo
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi,


    If you know the full name of the object that corresponds to the uninstallation program's main window, you can try using something like that:




    var UninstallWindow = <Uninstallation_Program_Main_Window>

    while (UninstallWindow.Exists)

    {

      Delay (100);

    }


    Does this help?

  • Thanks Irina for quick response for this.  That is MSI window and it put a class number in the name.  The following is what I get from Object Spy



    Window("#id", "product name", 1)



    and I believe the id number change every time when uninstall.  The only propery I can use is WndCaption, that is the name of the product.



    Btw, there is another problem in some Windows 7 environment when execute ClickItem  



        var programsList = wnd.FindChild("WndClass", "SysListView32", 20) 

        programsList.ClickItem(applicationName, 0);  <= I get "The window does not respond." error in testComplete result log.



    and the following messge in description


    The window with the 0x000303b4 handle exists but did not respond during the auto-wait timeout (10000 ms).



    Try increasing the 'Auto-wait timeout' project property.



    Tested object:

    Sys.Process("Explorer").Window("CabinetWClass", "Programs and Features", 1).Window("ShellTabWindowClass", "Programs and Features", 1).Window("DUIViewWndClassName", "", 1).Window("DirectUIHWND", "", 1).Window("CtrlNotifySink", "", 1).Window("SHELLDLL_DefView", "ShellView", 1).Window("SysListView32", "FolderView", 1)



    Incress auto-wait timeout doesn't help.



    Thanks


  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi,


    I believe the id number change every time when uninstall.  The only propery I can use is WndCaption, that is the name of the product.


    In this case, you'd better map the windows name using the WndCaption property that doesn't change and use the * mask instead of the identifier that may change from run to run.


    After you've mapped the needed window, use the mapped name in your test.


    Does this help?