How to automate uninstall of a program via autoit

autoit

I am trying to uninstall a program from add or remove programs via an AutoIt script.

*I dont want to uninstall via removing the registry keys.
* I dont want to uninstall via running an uninstaller.

I can open "add remove programs" by a appwiz.cpl command

However I am failing to recognize the correct program name from the list and invoke an uninstall.

All I want to do is recognize my program from the list, for example "Helloworld" and invoke an uninstall.

Best Solution

You can just loop through all your corresponding Registry Values of which your uninstall list in your "Add or remove programs" is made of... And then directly extract the command that you want to execute. I display it in a Message Box in this example, but you could directly compare the DisplayName to "Helloworld" and then execute the UninstallString with Run(...). This is the exact same as your "Add or remove programs" would invoke. It doesn't mean simply removing registry keys. And it doesn't mean just running "any" uninstaller but the proper one, needed to exactly uninstall this very program like clicking the "Uninstall" button in appwiz.cpl will invoke. So to perform what you asked for as a result, this solution works just fine. It does not acutally handle the appwiz.cpl and cycle through the list of programs...

$uninstall_path1 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall"
searchUninstallStrings($uninstall_path1)
$uninstall_path2 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
searchUninstallStrings($uninstall_path2)

Func searchUninstallStrings($uninstall_path)
    $i = 0
    While True
        $i += 1
        Local $entry = RegEnumKey($uninstall_path, $i)
        If @error <> 0 Then ExitLoop
        $regPath = $uninstall_path & "\" & $entry
        $DisplayName = RegRead($regPath, "DisplayName")
        If $DisplayName <> "" Then
            $message = $DisplayName & @CR
            $UninstallString = RegRead($regPath, "UninstallString")
            If $UninstallString <> "" Then
                $message &= "Uninstall: '" & $UninstallString & "'"
                MsgBox(4096, "SubKey #" & $i & ": " & $entry, $message)
            EndIf
        EndIf
    WEnd
EndFunc

Good Luck!

Related Question