0

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

4

1 回答 1

1

您可以使用最初发布在此处的 Craig McQueen 的解决方案:InnoSetup:如何自动卸载以前安装的版本?

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;
于 2012-07-17T13:18:28.203 回答