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?
Asked
Active
Viewed 248 times
0
-
Are you executing uninstaller before any part of installation starts - usually in InitializeSetup() ? Are you sure target directory (directory where unins000.exe should be placed) is correct? – Slappy Jul 17 '12 at 05:36
-
Are you using `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 from `PrepareToInstall`. No earlier, no later. – Miral Jul 17 '12 at 09:12
-
I am starting the uninstall in CurStepChanged (CurStep=ssInstall) per the post that I referenced. Uninstallable=yes. I need to run an uninstall because I have services that need to be shutdown and gracefully before an upgrade can be done. I'll try and change the uninstall step to PrepareToInstall. – Dan Jul 17 '12 at 11:29
-
You could place your Check and Call for UninstallOld in `function InitializeSetup: Boolean;` - there you could place a check if app is installed then call uninstall with `waituntilterminated`. In fact you could use solution by Craig McQueen that can be found here: http://stackoverflow.com/questions/2000296/innosetup-how-to-automatically-uninstall-previous-installed-version – RobeN Jul 17 '12 at 11:45
-
@RobeN That is the exact post I referenced in my question. I am using the Craig McQueen solution. – Dan Jul 17 '12 at 12:31
-
@Dan In that case if you place all your checks and calls in function mentioned above, the install process should not be affected by any way and Uninstall should be created. Maybe you could post you `[CODE]` so that SO Members could look into and find possible issue? – RobeN Jul 17 '12 at 12:47
1 Answers
1
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;