Nico Z
Nico Z

Reputation: 1027

How to prevent installation when application is installed already with Inno Setup?

I've installed my program. But if I try to install it again, it does and the program is replaced.

I saw this question How to display notifying message while installing with Inno Setup if application is already installed on the machine?

Can I create a certain registry entry so I can check it and prevent a new installation? In this question there is some related information: Skip installation in Inno Setup if other program is not installed.

Upvotes: 6

Views: 5951

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202232

You do not need to create any registry key. The installer already creates a registry key for the uninstaller. You can just check that. It's the same key, that the answer to question, you refer to, uses. But you do not need to do the check for version. Just check an existence. Also you should check both the HKEY_LOCAL_MACHINE and the HKEY_CURRENT_USER:

#define AppId "myapp"

[Setup]
AppId={#AppId}

[Code]

function InitializeSetup(): Boolean;
begin
  Result := True;
  if RegKeyExists(HKEY_LOCAL_MACHINE,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#AppId}_is1') or
     RegKeyExists(HKEY_CURRENT_USER,
       'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#AppId}_is1') then
  begin
    MsgBox('The application is installed already.', mbInformation, MB_OK);
    Result := False;
  end;
end;

The application is installed already


Or just reuse IsUpgrade function from Can Inno Setup respond differently to a new install and an update?

Upvotes: 11

Related Questions