I have a Inno Setup that runs the uninstaller of the older version if it was installed. In case that the uninstall process takes place the directory page is disabled what leads to an internal error because constant app
is not initialized.
The new version (1.3) is no more uninstallable, but I need to run the uninstaller if versions 1.1 or 1.2 where installed previous. Since this is a addon for an existing program i need to find it's directory. I try to extract this information from the registry and save information about the addon installation in the registry, too. This is where i find the uninstaller path in case that the previous version was installed and run it before i continue with the install process
[Setup]
…
DefaultDirName={commonpf32}\LucasArts\Star Wars Battlefront II\GameData\
AppendDefaultDirName=no
…
Uninstallable=no
DisableWelcomePage=no
DirExistsWarning=no
DisableProgramGroupPage=yes
…
[Registry]
Root: HKCU; Subkey: "Software\GTAnakin"; Flags: uninsdeletekeyifempty
Root: HKCU; Subkey: "Software\GTAnakin\SWBF2REMASTER"; Flags: uninsdeletekey
…
[Code]
…
procedure InitializeWizard;
var
UrlLabel : TNewStaticText;
CancelBtn : TButton;
UninstPath : string;
iResult : integer;
InstallDir : string;
begin
CancelBtn := WizardForm.CancelButton;
UrlLabel := TNewStaticText.Create(WizardForm);
UrlLabel.Top := CancelBtn.Top + (CancelBtn.Height div 2) - (UrlLabel.Height div 2);
UrlLabel.Left := WizardForm.ClientWidth - CancelBtn.Left - CancelBtn.Width;
UrlLabel.Caption := ExpandConstant('{cm:txtHomePageLink}');
UrlLabel.Font.Style := UrlLabel.Font.Style + [fsUnderline];
UrlLabel.Cursor := crHand;
UrlLabel.Font.Color := clHighlight;
UrlLabel.OnClick := @UrlLabelClick;
UrlLabel.Parent := WizardForm;
WizardForm.DirEdit.Text := '';
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\LucasArts\Star Wars Battlefront II\1.0','ExePath', InstallDir) then begin
if FileExists(InstallDir) then begin
InstallDir := ExtractFilePath(InstallDir);
delete(InstallDir,length(InstallDir),1);
WizardForm.DirEdit.Text := InstallDir;
end;
end;
if RegQueryStringValue(HKEY_CURRENT_USER, 'Software\GTAnakin\SWBF2REMASTER', 'UninstPath', UninstPath) then begin
Exec(UninstPath, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResult)
end;
end;
…
I expect that the setup tries to auto detect the install path from the registry and predefines the app
constant. The directory page should be displayed always, so the user can check and change the path. But the directory page is only shown if there was no previous version to uninstall. Otherwise the page is skipped and lead to the internal error if the path couldn't be autodetected.
Move your uninstall code to InitializeSetup
event function.
InitializeSetup
is triggered before the DisableDirPage
is directive evaluated (contrary to InitializeWizard
that you use currently). And your code belongs there anyway.