Jump to content
Sign in to follow this  
Quinch

Uninstalling programs through windows GUI?

Recommended Posts

Quinch

This has probably been asked before, but I haven't had any luck finding an answer.

Is there a way to use AutoIt to remove programs via Windows' "Add/Remove Programs" window? I know that there are built-in functions that should be able to uninstall applications via command line, but a lot of OEM crapware tends to be installed in kinda dodgy ways. Thus, is there a way to examine the installed programs list for a matching blacklist entry and select it {the rest I can kludge from there}?

Share this post


Link to post
Share on other sites
JLogan3o13

@Quinch I service a lot of customers that have home-grown or "dodgy" applications, and use a combination of Registry Reads and WMI to search for installed applications. As the Add/Remove Programs GUI is just pulling information from these sources, if it is there it will either be in the registry or WMI. Below are the two ways to do so:

WMI:

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7

;====Get Installed Applications
Local $sPC, $oWMI, $aSystem

$sPC = "<machine name>"
    If Ping($sPC) Then
        $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sPC & "\root\cimv2")
            If IsObj($oWMI) Then
                $aSystem = $oWMI.ExecQuery("Select * from Win32_Product")
                    For $sApp In $aSystem
                        ConsoleWrite("Application: " & $sApp.Name & " Version: " & $sApp.Version & @CRLF)
                    Next
            Else
                ConsoleWrite("Unable to connect to WMI on " & $sPC & @CRLF)
            EndIf
    Else
        ConsoleWrite("Unable to Ping " & $sPC & @CRLF)
    EndIf

And Registry, something like this (slight tweaking if you're mixing x86 and x64 machines):

Local $sKey, $sKey64, $sSubKey
    $sKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

For $a = 1 To 200
    $sSubKey = RegEnumKey($sKey, $a)
        If @error Then ExitLoop
    ConsoleWrite(RegRead($sKey & $sSubKey, "DisplayName") & @CRLF)
Next

 

Edited by JLogan3o13
  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Quinch

That helps in listing the stuff, but how do I get it to bring up the uninstaller? And I mean the uninstaller, unfortunately, given the dodgy methods some of this stuff hooks into the system.

Edit: It doesn't seem to list all of the software either - most of it, but not all.

Edited by Quinch

Share this post


Link to post
Share on other sites
orbs

@Quinch,

in WMI, the Win32_Product object has a method called "uninstall". call it to... well... uninstall the product.

in the registry, each installed program has the value "UninstallString", which is the command line you need to run to uninstall the product.

3 hours ago, Quinch said:

It doesn't seem to list all of the software either - most of it, but not all.

installed products may or may not register themselves in various locations. you may need to incorporate both methods (and accommodate for x86 and x64, as stated).

  • Like 1

Share this post


Link to post
Share on other sites
Quinch

Ahh, got it - I forgot to tweak the registry entry for the x64 architecture. It seems to work - so theoretically, {can someone confirm for sure?} I can run the UninstallString from the registry to launch the uninstaller?

Also, another silly question - how do I call the WMI uninstall method from AutoIt?

Share this post


Link to post
Share on other sites
JLogan3o13

Yes, you can do a RegRead on the uninstall value in the key, and then shellexecute that. For WMI, you would do something like this:

#include <MsgBoxConstants.au3>

$sName = InputBox("Uninstall Wizard", "Please type the first few letters of the application name to search")
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")
$aProducts = $oWMI.ExecQuery("Select * from Win32_Product Where Name LIKE '%" & $sName & "%'")

For $app in $aProducts
    $popup = MsgBox($MB_YESNOCANCEL, "Uninstall Wizard", "Would you like to uninstall " & $app.Name & "?")
        If $popup = $IDYES Then
            $app.Uninstall()
        ElseIf $popup = $IDCANCEL Then
            ExitLoop
        EndIf
Next

 

  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Quinch

Hooray, it seems to work! Now let's see if I can get approval to use AutoIt at work....

But one way or another, thanks hugely for the help!

Edited by Quinch

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  

×