0

I tried to uninstall previous version which installed by InstallShield.

function GetUninstallString(): String;
var
    sUnInstPath: String;
    sUnInstallString: String;
begin
    sUnInstPath := ExpandConstant('SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{{OldAppID}');
    sUnInstallString := '';
    if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString)then 
        RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
    MsgBox(sUnInstallString, mbInformation, MB_OK);
    Result := sUnInstallString;
end;

function UninstallOldVersion(): Integer;
var
    sUnInstallString: String;
    iResultCode: Integer;
begin
//  Returb Values:
//  1 - uninstall string is empty
//  2 - error executing the UnInstallString
//  3 - successfully executed the UnInstalString    

    //default return value
    Result := 0;

    //get the uninstall string of the old app
    sUnInstallString := GetUninstallString();                     
    if sUnInstallString <> '' then begin
        sUnInstallString:= RemoveQuotes(sUnInstallString);

        if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES', '', SW_HIDE, ewWaitUntilTerminated, iResultCode) then begin
            Result := 3
            MsgBox('3', mbInformation, MB_OK);
        end
        else begin
            Result := 2
            MsgBox('2', mbInformation, MB_OK);
        end;
    end else begin
        Result := 1 
        MsgBox('1', mbInformation, MB_OK);
        end;
end;

The result of UninstallOldVersion() is '3' but the old version didn't uninstall actually.

The result of GetUninstallString():

"C:\Program Files (x86)\InstallShield Installation Information\{OldAppID}\setup.exe" -runfromtemp -l0x0409  -removeonly
Assam
  • 179
  • 1
  • 13
  • 1
    It works. Thanks a lot! – Assam Nov 07 '19 at 07:34
  • Martin, There is a another problem. The install procedure is early then uninstall procedure. How could i do? I have added ewWaitUntilTerminated flag. – Assam Nov 07 '19 at 08:40
  • 1
    I add /clone_wait. Thanks for your another answer. https://stackoverflow.com/questions/49893227/inno-setup-exec-doesnt-wait-for-installshield-uninstallation-to-complete/49895526#49895526 – Assam Nov 07 '19 at 08:54

0 Answers0