How to detect old installation and offer removal?

Viewed 31709

How do I detect whether the user already installed the software and if so, how to offer the possibility of removing the old version?

I have written some lines to check that. Is that correct for now? If this is correct, then how can I let the user choose whether he wants to continue the installation or uninstall the old version?

#define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\setupname_is1"

var
  uninstallPath: string;

function InitializeSetup: Boolean;
begin
  if (RegQueryStringValue(HKLM,'{#UNINSTKEY}','UninstallString',uninstallPath)) and
     (uninstallPath <> '') and (fileexists(uninstallPath)) then
  begin
    Result :=
      (MsgBox(CustomMessage('NotVerifiedVersionFound'), mbConfirmation,
              MB_YESNO or MB_DEFBUTTON2) = IDYES);
  end;
  { ... }
end;
2 Answers

For anyone interested, I wrote a small DLL for Inno Setup 6 and newer that provides the ability to detect if an application is installed and to automatically uninstall the previous installed version based on your own criteria.

https://github.com/Bill-Stewart/UninsIS

Using the DLL you can automatically uninstall only when downgrading, only when upgrading, or either.

Related