Dan
Dan

Reputation: 1389

uninstaller is not created after version upgrade

I have setup my installer to use the code referred to in this post to check for an existing version and then calling uninstall on it before installing the new version. Works great. My problem is that after the uninstall / install steps the new versions uninstall (unins000.exe) is not created (or maybe it was but is deleted IDK). This prevents the new version from being uninstalled properly later. The uninstaller is always created if there isn't an existing version. What am I doing wrong?

Upvotes: 0

Views: 306

Answers (1)

RobeN
RobeN

Reputation: 5456

You could use Craig McQueen's solution originally posted here: InnoSetup: How to automatically uninstall previous installed version?

function GetUninstallString(): String;
var
    sUnInstPath: String;
    sUnInstallString: String;
    begin
        sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{{A227028A-40D7-4695-8BA9-41DF6A3895C7}_is1'); //Your App GUID/ID
        sUnInstallString := '';
            if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
                RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
                Result := sUnInstallString;
    end;

function IsUpgrade(): Boolean;
    begin
        Result := (GetUninstallString() <> '');
    end;

function InitializeSetup: Boolean;
var
    V: Integer;
    iResultCode: Integer;
    sUnInstallString: String;
    begin
        if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\{A227028A-40D7-4695-8BA9-41DF6A3895C7}_is1', 'UninstallString') then begin
//Your App GUID/ID
            V := MsgBox(ExpandConstant('{cm:YesNoUninstall}'), mbInformation, MB_YESNO); //Custom Message if App installed
            if V = IDYES then begin
                sUnInstallString := GetUninstallString();
                sUnInstallString :=  RemoveQuotes(sUnInstallString); 
                Exec(ExpandConstant(sUnInstallString), '', '', SW_SHOW, ewWaitUntilTerminated, iResultCode);
                Result := True; //if you want to proceed after uninstall
                //Exit; //if you want to quit after uninstall
            end
            else begin
                Result := False; //when older version present and not uninstalled
            end;
        end
        else begin
            Result := True; //when no previous version found   
        end;
    end;

Upvotes: 1

Related Questions