Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

inno setup - How to allow installation only to a specific folder?

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...