Jump to content

Multi Program Uninstaller


Fen
 Share

Recommended Posts

Hey all. I'm new to Autoit scripting and looking for some help.

I located this zippy little program from lunj Posted on 28 April 2010 - 05:12 PM.

It works very well, and I did some modification to it to uninstall a program I've been after. The problem though, is I need to remove 5 programs in one fell swoop. I could use this program to do it, and just change it for each one, but I would love to string them all together.

My other conundrum is that all 5 may not be installed every time. Sometime it may only be 3 of the 5 installed.

I'm trying to experiment with IF THEN statements, but I'm missing something. Any help would be appreciated.

$sBase = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" 
$iEval = 1 
$sSearch = "Fiery" 
While 1 
    $sUninst = "" 
    $sDisplay = "" 
    $sCurrent = RegEnumKey($sBase, $iEval) 
    If @Error Then ExitLoop 
    $sKey = $sBase & $sCurrent 
    $sDisplay = RegRead($sKey, "DisplayName") 
    If StringRegExp($sDisplay, "(?i).*" & $sSearch & ".*") Then 
        $sUninst = RegRead($sKey, "UninstallString") 
        If $sUninst Then 
            Run($sUninst) 
            WinwaitActive("Windows Installer")
            WinActive("Windows Installer")
                sleep(20)
            ControlClick("Windows Installer", "Are you sure you want to uninstall this product?", "Yes") 
                        
        EndIf 
    EndIf 
        $iEval += 1 
WEnd
Link to comment
Share on other sites

Create five different uninstall scripts then make one script that manages them all. The manager script detects what of the five programs are installed on the system then runs the corresponding uninstaller scripts in sequence.

EDIT: This approach has the added advantage of flexibility, if you structure your manager script correctly.

Edited by omikron48
Link to comment
Share on other sites

Hey all. I'm new to Autoit scripting and looking for some help.

I located this zippy little program from lunj Posted on 28 April 2010 - 05:12 PM.

It works very well, and I did some modification to it to uninstall a program I've been after. The problem though, is I need to remove 5 programs in one fell swoop. I could use this program to do it, and just change it for each one, but I would love to string them all together.

My other conundrum is that all 5 may not be installed every time. Sometime it may only be 3 of the 5 installed.

I'm trying to experiment with IF THEN statements, but I'm missing something. Any help would be appreciated.

$sBase = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" 
$iEval = 1 
$sSearch = "Fiery" 
While 1 
    $sUninst = "" 
    $sDisplay = "" 
    $sCurrent = RegEnumKey($sBase, $iEval) 
    If @Error Then ExitLoop 
    $sKey = $sBase & $sCurrent 
    $sDisplay = RegRead($sKey, "DisplayName") 
    If StringRegExp($sDisplay, "(?i).*" & $sSearch & ".*") Then 
        $sUninst = RegRead($sKey, "UninstallString") 
        If $sUninst Then 
            Run($sUninst) 
            WinwaitActive("Windows Installer")
            WinActive("Windows Installer")
                sleep(20)
            ControlClick("Windows Installer", "Are you sure you want to uninstall this product?", "Yes") 
                        
        EndIf 
    EndIf 
        $iEval += 1 
WEnd

It looks like it'll just exit if it can't find the Uninstall for that program (ExitLoop).

If it's a set 5, then just copy and paste it 5 times changing the values? Or, you could make a 2 dimensional array and do a For Loop setting $sBase, $iEval, and $sSearch with relevant value, running the script, then processing the next one. Helpfile has useful examples.

Link to comment
Share on other sites

  • 1 month later...

How could a person make the above code work unattended so you can have the script uninstall automatically when done move on to the next one? I am trying to figure out an automatic uninstall for many programs but I don't want to have to click on OK Next Finish every time.

Link to comment
Share on other sites

Here are some MSI uninstall functions that I wrote. These only work with MSI installs and will not uninstall other install methods. It will search for the name with partial search method. The functions can take a string for a single uninstall search or an array for multiple. I have used these many times for writing installs for applications that require the previous versions to be uninstalled.

;Examples
Global $aUninstApps[3] = ["QuickTime", "Apple Software Update", "Apple Application Support"]

_UninstallMSISoftwareLimitedUI($aUninstApps)
_UninstallMSISoftwareLimitedUI("QuickTime")

_UninstallMSISoftwareLimitedUIWithMsgBox($aUninstApps)
_UninstallMSISoftwareLimitedUIWithMsgBox("QuickTime")

_UninstallMSISoftwareNoUI($aUninstApps)
_UninstallMSISoftwareNoUI("QuickTime")


Func _UninstallMSISoftwareLimitedUI($vAppName) ;Uninstalls showing only the progress bar.
    $iInstalledAppsCount = 1
    $iFound = 0

    While 1

        $sSubKey = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $iInstalledAppsCount)
        If @error Then ExitLoop

        $sDisplayName = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "DisplayName")
        $sUninstallString = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "UninstallString")

        If IsArray($vAppName) Then
            For $i = 0 To UBound($vAppName)-1
                If StringInStr($sDisplayName, $vAppName[$i]) And StringInStr($sUninstallString, "msiexec") Then
                    $iFound += 1
                    If Not StringInStr($sUninstallString, "/qb") And Not StringInStr($sUninstallString, "/qn") Then
                        $sUninstallString &= " /qb! REBOOT=ReallySuppress"
                    ElseIf StringInStr($sUninstallString, "/qn") Then
                        $sUninstallString = StringReplace($sUninstallString,"/qn","/qb! REBOOT=ReallySuppress")
                    EndIf
                    RunWait(StringReplace($sUninstallString,"/I{","/X{"),"")
                EndIf
            Next
        ElseIf IsString($vAppName) Then
            If StringInStr($sDisplayName, $vAppName) And StringInStr($sUninstallString, "msiexec") Then
                $iFound += 1
                If Not StringInStr($sUninstallString, "/qb") And Not StringInStr($sUninstallString, "/qn") Then
                    $sUninstallString &= " /qb! REBOOT=ReallySuppress"
                ElseIf StringInStr($sUninstallString, "/qn") Then
                    $sUninstallString = StringReplace($sUninstallString,"/qn","/qb! REBOOT=ReallySuppress")
                EndIf
                RunWait(StringReplace($sUninstallString,"/I{","/X{"),"")
            EndIf

        Else
            Return SetError(1, 0, 0)

        EndIf

        $iInstalledAppsCount += 1

    WEnd

    If Not $iFound Then Return 0

    Return 1
EndFunc

Func _UninstallMSISoftwareLimitedUIWithMsgBox($vAppName) ;Uninstalls asking Yes or No with a MsgBox for each App found showing only the progress bar while uninstalling.
    $iInstalledAppsCount = 1
    $iFound = 0

    While 1

        $sSubKey = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $iInstalledAppsCount)
        If @error Then ExitLoop

        $sDisplayName = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "DisplayName")
        $sUninstallString = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "UninstallString")

        If IsArray($vAppName) Then
            For $i = 0 To UBound($vAppName)-1
                If StringInStr($sDisplayName, $vAppName[$i]) And StringInStr($sUninstallString, "msiexec") Then
                    $iFound += 1
                    If Not StringInStr($sUninstallString, "/qb") And Not StringInStr($sUninstallString, "/qn") Then
                        $sUninstallString &= " /qb! REBOOT=ReallySuppress"
                    ElseIf StringInStr($sUninstallString, "/qn") Then
                        $sUninstallString = StringReplace($sUninstallString,"/qn","/qb! REBOOT=ReallySuppress")
                    EndIf
                    #Region --- CodeWizard generated code Start ---
                    ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Question
                    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
                    $iMsgBoxAnswer = MsgBox(36,"Uninstall " & $sDisplayName,"Would you like to uninstall " & $sDisplayName & "?")
                    Select
                        Case $iMsgBoxAnswer = 6 ;Yes
                            RunWait(StringReplace($sUninstallString,"/I{","/X{"),"")
                        Case $iMsgBoxAnswer = 7 ;No

                    EndSelect
                    #EndRegion --- CodeWizard generated code End ---


                EndIf
            Next
        ElseIf IsString($vAppName) Then
            If StringInStr($sDisplayName, $vAppName) And StringInStr($sUninstallString, "msiexec") Then
                $iFound += 1
                If Not StringInStr($sUninstallString, "/qb") And Not StringInStr($sUninstallString, "/qn") Then
                    $sUninstallString &= " /qb! REBOOT=ReallySuppress"
                ElseIf StringInStr($sUninstallString, "/qn") Then
                    $sUninstallString = StringReplace($sUninstallString,"/qn","/qb! REBOOT=ReallySuppress")
                EndIf
                #Region --- CodeWizard generated code Start ---
                ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Question
                If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
                $iMsgBoxAnswer = MsgBox(36,"Uninstall " & $sDisplayName,"Would you like to uninstall " & $sDisplayName & "?")
                Select
                    Case $iMsgBoxAnswer = 6 ;Yes
                        RunWait(StringReplace($sUninstallString,"/I{","/X{"),"")
                    Case $iMsgBoxAnswer = 7 ;No
                    EndSelect
                #EndRegion --- CodeWizard generated code End ---


            EndIf

        Else
            Return SetError(1, 0, 0)

        EndIf

        $iInstalledAppsCount += 1

    WEnd

    If Not $iFound Then Return 0

    Return 1
EndFunc

Func _UninstallMSISoftwareNoUI($vAppName) ;Uninstalls silently.
    $iInstalledAppsCount = 1
    $iFound = 0

    While 1

        $sSubKey = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $iInstalledAppsCount)
        If @error Then ExitLoop

        $sDisplayName = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "DisplayName")
        $sUninstallString = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "UninstallString")

        If IsArray($vAppName) Then
            For $i = 0 To UBound($vAppName)-1
                If StringInStr($sDisplayName, $vAppName[$i]) And StringInStr($sUninstallString, "msiexec") Then
                    $iFound += 1
                    If Not StringInStr($sUninstallString, "/qb") And Not StringInStr($sUninstallString, "/qn") Then
                        $sUninstallString &= " /qn REBOOT=ReallySuppress"
                    ElseIf StringInStr($sUninstallString, "/qb") Then
                        $sUninstallString = StringReplace($sUninstallString,"/qb","/qn REBOOT=ReallySuppress")
                    EndIf
                    RunWait(StringReplace($sUninstallString,"/I{","/X{"),"")
                EndIf
            Next
        ElseIf IsString($vAppName) Then
            If StringInStr($sDisplayName, $vAppName) And StringInStr($sUninstallString, "msiexec") Then
                $iFound += 1
                If Not StringInStr($sUninstallString, "/qb") And Not StringInStr($sUninstallString, "/qn") Then
                    $sUninstallString &= " /qn REBOOT=ReallySuppress"
                ElseIf StringInStr($sUninstallString, "/qb") Then
                    $sUninstallString = StringReplace($sUninstallString,"/qb","/qn REBOOT=ReallySuppress")
                EndIf
                RunWait(StringReplace($sUninstallString,"/I{","/X{"),"")
            EndIf

        Else
            Return SetError(1, 0, 0)

        EndIf

        $iInstalledAppsCount += 1

    WEnd

    If Not $iFound Then Return 0

    Return 1
EndFunc

Adam

Link to comment
Share on other sites

@nightr1701

Your welcome. Glad I could help.

Just a FYI. If you include the functions unchanged in a script compiled for x86, it will read that node, Wow6432node, through the windows redirection mechanism for x64. That how I compile scripts, if it is a 32 bit application that I am installing, and need to uninstall the previous version.

Adam

Link to comment
Share on other sites

@nightr1701

For non MSI, you have do find out what the installation program is and if it has switches for silent uninstallation. The clues are usually in the uninstall string.

For example InstallShield, you can do a silent uninstall, but you have to create an uninstall ISS answer file with the "/r /f1c:\uninstall.iss" switches following the uninstall string. You will then have to click through the uninstall while it records you responses. You can then use the "/s /f1c:\uninstall.iss" switches to silently uninstall it with your script. I usually do this on a VM with snapshots to create the ISS files and test the uninstalls. Also, if I am installing a new application that uses InstallShield, I record an install.iss and an uninstall.iss. This makes it easier for uninstallation down the road, when we get a new version.

Appdeploy.com is a good resource for information on silent installations and uninstallations using different methods and what command line switches are for different installers.

Adam

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