How to allow installation only to a specific folder?

inno-setup

Solution

The following sample shows how to disable the `Next` button when you reach the `SelectDir` page and enable it only when you enter (or choose from the browse directory dialog) the `C:\MySecretDir` folder (the `MySecretDir` constant). The comparing is case insensitive since user can enter whatever he (or she) wants.

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
const
  MySecretDir = 'C:\MySecretDir';

procedure OnDirEditChange(Sender: TObject);
begin
  WizardForm.NextButton.Enabled := CompareText(WizardDirValue, MySecretDir) = 0;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = wpSelectDir then
    OnDirEditChange(nil);
end;

procedure InitializeWizard;
begin
  WizardForm.DirEdit.OnChange := @OnDirEditChange;
end;

Or if you want to enable the `Next` button only if there's a specific file `MyUniqueFile.exe` in the chosen directory, modify the code in `OnDirEditChange` event handler this way:

procedure OnDirEditChange(Sender: TObject);
begin
  WizardForm.NextButton.Enabled := FileExists(AddBackslash(WizardDirValue) +
    'MyUniqueFile.exe');
end;

Problem

I would like to install my setup content only to one specific directory, so I want to have the `Next` button on directory selection page disabled, unless the user chooses the right folder to install to. How can I disable the `Next` button on directory selection page and enable it right after user chooses a specific directory ?

Original source