Jump to content
Serg_K

Script to check existing uninstall guid in registry

Recommended Posts

Serg_K

Hi all,

i am very new in autoit and want to learn a bit more about, but now I have a topic which I have to resolve quickly.
We do have installed a several versions of Enterprise Vault in our company and I want to bring them up to the newest one, but before I can install the newest one I have to uninstall the already installed "old" version.

My Idea was, first to check which version is installed, and then uninstall this via the specific uninstall string like " msiexec /x 9F89F857-ADEB-4916-9D7B-2859DAC597DF"

What I already found and did is:

Local $var[3]
$var[0] = "{9F89F857-ADEB-4916-9D7B-2859DAC597DF}" ;10.0.13477
$var[1] = "{2C24C6C3-41A0-4E19-8EAE-78E9C928433E}";10.0.3.1169
$var[2] = "{4B99E166-E028-4FC2-BF8D-FB40CE0A6FAE}" ;11.0.1.3674



For $element in $var
    RunWait('msiexec /x "' & $element & '"')
 Next

 

But this only fills the variable and runs it 3 times, do you have an Idea how I can solve this ?

 

 

 

Share this post


Link to post
Share on other sites
Zedna

Generally you can read and test content of this Registry Uninstall section:

"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall"

There are keys: DisplayName, DsiplayVersion, ...
 

Share this post


Link to post
Share on other sites
Earthshine

Just loop for as many times as you have things to uninstall. What’s that element you’re looking at it’s not even declared. Also check the registry key as was mentioned above to find the guid that you were interested in removing

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

If you know the guid of these products you can simply search, put them in an array then loop for those elements in the array and run the uninstall string that’s in the registry for each


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Serg_K

I did, but still not working

 

Func searchUninstallStrings($uninstall_path)

Local $var[4]
$var[0] = "{9F89F857-ADEB-4916-9D7B-2859DAC597DF}" ;10.0.13477
$var[1] = "{2C24C6C3-41A0-4E19-8EAE-78E9C928433E}";10.0.3.1169
$var[2] = "{4B99E166-E028-4FC2-BF8D-FB40CE0A6FAE}" ;11.0.1.3674
$var[3] = "{E6BD5A9E-65E0-4139-A535-0D9FF61443FF}" ;12.1.13856

    $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 $entry = "{9F89F857-ADEB-4916-9D7B-2859DAC597DF}" Then
               RunWait($UninstallString)
                                   ElseIf $entry = "{2C24C6C3-41A0-4E19-8EAE-78E9C928433E}" Then
                                      RunWait('msiexec /x "' & $var[1] & '"')
                                   ElseIf $entry = "{4B99E166-E028-4FC2-BF8D-FB40CE0A6FAE}" Then
                                      RunWait('msiexec /x "' & $var[2] & '"')
                                   ElseIf $entry = "{E6BD5A9E-65E0-4139-A535-0D9FF61443FF}" Then
                                      ;RunWait('msiexec /x "' & $var[3] & '"')
                                      RunWait($UninstallString)
                                      $CMD =
                                   EndIf
           If $UninstallString <> "" Then
               ;$message &= "Uninstall: '" & $UninstallString & "'"
               ;MsgBox(4096, "SubKey #" & $i & ": " & $entry, $message)
           EndIf
         EndIf

    WEnd
EndFunc

Func searchUninstallStrings($uninstall_path)

Local $var[4]
$var[0] = "{9F89F857-ADEB-4916-9D7B-2859DAC597DF}" ;10.0.13477
$var[1] = "{2C24C6C3-41A0-4E19-8EAE-78E9C928433E}";10.0.3.1169
$var[2] = "{4B99E166-E028-4FC2-BF8D-FB40CE0A6FAE}" ;11.0.1.3674
$var[3] = "{E6BD5A9E-65E0-4139-A535-0D9FF61443FF}" ;12.1.13856

    $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 $entry = "{9F89F857-ADEB-4916-9D7B-2859DAC597DF}" Then
               RunWait($UninstallString)
                                   ElseIf $entry = "{2C24C6C3-41A0-4E19-8EAE-78E9C928433E}" Then
                                      RunWait('msiexec /x "' & $var[1] & '"')
                                   ElseIf $entry = "{4B99E166-E028-4FC2-BF8D-FB40CE0A6FAE}" Then
                                      RunWait('msiexec /x "' & $var[2] & '"')
                                   ElseIf $entry = "{E6BD5A9E-65E0-4139-A535-0D9FF61443FF}" Then
                                      ;RunWait('msiexec /x "' & $var[3] & '"')
                                      RunWait($UninstallString)
                                      $CMD =
                                   EndIf
           If $UninstallString <> "" Then
               ;$message &= "Uninstall: '" & $UninstallString & "'"
               ;MsgBox(4096, "SubKey #" & $i & ": " & $entry, $message)
           EndIf
         EndIf

    WEnd
EndFunc

 

  • Like 1

Share this post


Link to post
Share on other sites
Earthshine

hang on mate.... here is how i did it in a patch i made a long time ago. you can figure out a for or while loop, I am sure. Lets get simple and do this the once, then make a loop.

prototype NUMBER UninstallSetup(STRING, BOOL);

//---------------------------------------------------------------------------
//  FUNCTION:   UninstallSetup
//  In:         szOldKey -- the old key of the app you want to delete
//  Out:        None
//  PURPOSE:    Uninstall a given setup given the product GUID
//  RETURNS:    None
//---------------------------------------------------------------------------
function UninstallSetup(szOldKey, bBool)

STRING szKey, svValue, szUninstValue, firststring, svString, secondstring;
NUMBER nvSize, nType, nResult, numResult;
LIST listID;

begin
 nType = REGDB_NUMBER;
 szUninstValue = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{" + szOldKey + "}";
 RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);

 // Retrieve the uninstallation string.

 if (RegDBGetKeyValueEx(szUninstValue, "UninstallString", nType, svValue, nvSize) == 0) then
    listID = ListCreate ( STRINGLIST );
    StrGetTokens ( listID , svValue , "\"" );
    nResult = ListGetFirstString (listID, svString);
    firststring = svString;

    // Loop while list items continue to be retrieved.
    while (nResult != END_OF_LIST)
        // Get the next string in the list.
        nResult = ListGetNextString (listID, svString);
        numResult = StrFind ( svString , "setup.exe" );
        LongPathToQuote ( svString , TRUE );
        if (numResult > 0)then
            secondstring = svString;
        endif;
        if (bBool) then
            secondstring = svString + " /s UNINSTALL";
        endif;
    endwhile;

    //MessageBox(firststring, INFORMATION);
    //MessageBox(secondstring, INFORMATION);
    if (LaunchAppAndWait (firststring, secondstring, LAAW_OPTION_WAIT) < 0) then
        MessageBox("Failed to Remove the Application", SEVERE);
    endif;
 endif;
end;

this is how i do it in InstallScript. Don't mind the list stuff, you can glean out logic, make it a function you pass the guid to and do something, then just loop calling your function with each list element. I would put your stuff in an array and just loop it, calling your function to remove the app. Also, that secondstring is just so i could cat on a /s so our stupid InstallScript installs uninstall silent... lol, you won't need that. Don't bass a boolean as a second param to your function.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Subz

Another example, since you know the Guid no need to use RegEnumKey

#RequireAdmin
#include <Misc.au3>

searchUninstallStrings("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\")
searchUninstallStrings("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\")

Func searchUninstallStrings($sRegUninstallPath)
    Local $sUninstallString
    Local $aUninstall[4][2]
        $aUninstall[0][1] = "{9F89F857-ADEB-4916-9D7B-2859DAC597DF}"
        $aUninstall[0][1] = "10.0.13477"
        $aUninstall[1][0] = "{2C24C6C3-41A0-4E19-8EAE-78E9C928433E}"
        $aUninstall[1][1] = "10.0.3.1169"
        $aUninstall[2][0] = "{4B99E166-E028-4FC2-BF8D-FB40CE0A6FAE}"
        $aUninstall[2][1] = "11.0.1.3674"
        $aUninstall[3][0] = "{E6BD5A9E-65E0-4139-A535-0D9FF61443FF}"
        $aUninstall[3][1] = "12.1.13856"

    For $i = 0 To UBound($aUninstall) - 1
        If StringRight($sRegUninstallPath, 1) = "\" Then
            $sRegUninstallPath &= $aUninstall[$i][0]
        Else
            $sRegUninstallPath &= "\" & $aUninstall[$i][0]
        EndIf
        $sUninstallString = _VersionCompare($aUninstall[$i][1], RegRead($sRegUninstallPath, "DisplayVersion")) = 0 ? RegRead($sRegUninstallPath, "UninstallString") : ""
            If $sUninstallString = "" Then ContinueLoop
        RunWait("MsiExec.exe /x " & $aUninstall[$i][0] & " /qb /norestart")
    Next
EndFunc

 

  • Like 1

Share this post


Link to post
Share on other sites
Earthshine

dude, you just give it away subz :) that is EXACTLY what I envision for the AutoIt world. you supposed to lead them to the solution.... lolz

with exception

I would make the function just do one at a time and return. loop on all your elements, just making one clean function call passing the elements as parameters. It is more flexible and reusable for one thing. And can be reused no matter how many elements are in the array. ;), or even better, just pass it an array and let it rip! process each uninstall, that way it's ONE function call.

#RequireAdmin
#include <Misc.au3>

searchUninstallStrings("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\")
searchUninstallStrings("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\")


Local $sUninstallString
Local $aUninstall[4][2]
$aUninstall[0][1] = "{9F89F857-ADEB-4916-9D7B-2859DAC597DF}"
$aUninstall[0][1] = "10.0.13477"
$aUninstall[1][0] = "{2C24C6C3-41A0-4E19-8EAE-78E9C928433E}"
$aUninstall[1][1] = "10.0.3.1169"
$aUninstall[2][0] = "{4B99E166-E028-4FC2-BF8D-FB40CE0A6FAE}"
$aUninstall[2][1] = "11.0.1.3674"
$aUninstall[3][0] = "{E6BD5A9E-65E0-4139-A535-0D9FF61443FF}"
$aUninstall[3][1] = "12.1.13856"

searchUninstallStrings($aUninstall)

Func searchUninstallStrings($aUninstall)
    For $i = 0 To UBound($aUninstall) - 1
        If StringRight($sRegUninstallPath, 1) = "\" Then
            $sRegUninstallPath &= $aUninstall[$i][0]
        Else
            $sRegUninstallPath &= "\" & $aUninstall[$i][0]
        EndIf
        $sUninstallString = _VersionCompare($aUninstall[$i][1], RegRead($sRegUninstallPath, "DisplayVersion")) = 0 ? RegRead($sRegUninstallPath, "UninstallString") : ""
        If $sUninstallString = "" Then ContinueLoop
        RunWait("MsiExec.exe /x " & $aUninstall[$i][0] & " /qb /norestart")
    Next
EndFunc

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Serg_K

Cool thank you, i will give i t a try :)

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

×