版本升级后不会创建卸载程序

时间:2012-07-16 16:50:32

标签: inno-setup

我已将安装程序设置为使用此post中引用的代码检查现有版本,然后在安装新版本之前调用uninstall。效果很好。我的问题是,在卸载/安装步骤后,新版本卸载(unins000.exe)未创建(或者可能是已删除IDK)。这可以防止以后正确卸载新版本。如果没有现有版本,则始终会创建卸载程序。我做错了什么?

1 个答案:

答案 0 :(得分:1)

您可以使用最初发布在此处的Craig McQueen解决方案: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;