Jump to content

Uninstalling programs through windows GUI?


Recommended Posts

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}?

Link to comment
Share on other sites

  • Moderators

@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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

@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).

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Moderators

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

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...