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?
0
votes
1 Answers
1
votes
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;
Uninstallable=no
or a similar option in your[Setup]
section? Also: generally it is not recommended to uninstall prior to an update. Just let the update install over the top and use[InstallDelete]
to get rid of any now-redundant files. Also-also, if you do end up running the uninstaller despite advice then you MUST do so fromPrepareToInstall
. No earlier, no later. – Miralfunction InitializeSetup: Boolean;
- there you could place a check if app is installed then call uninstall withwaituntilterminated
. In fact you could use solution by Craig McQueen that can be found here: stackoverflow.com/questions/2000296/… – RobeN