This question already has answers here:
Exit from Inno Setup installation from [Code]
(6 answers)
Inno Setup: How to abort/terminate setup during install?
(4 answers)
Closed 2 years ago.
What I want to do:
If the user clicks "Next" on wpWelcome and if an old version of the app is found on the computer, then I prompt a msgbox.
If the user clicks "cancel" on msgbox then I want to abort installation and close wizard without prompt, just like abort() with TSetupStep, but WizardForm.Close prompts another msgbox to confirm cancelation. Is there any way to suppress this?
My current code below:
function NextButtonClick(CurPage: Integer): Boolean;
begin
if (CurPage=wpWelcome) then
begin
if (AppAlreadyInstalled()) then
begin
if MsgBox('Another installation of {#MyAppName} has been detected.
Proceeding with "OK" will uninstall the existing program first.
Press "cancel" to abort and exit installer.',
mbConfirmation, MB_OKCANCEL or MB_DEFBUTTON2) = IDOK then
begin
UnInstallOldVersion();
Result:= True;
end
else
begin
Result:= False;
WizardForm.Close;
end;
end;
end;
end;
Related
I am trying to do something similar to this.
Do a version check after Welcome page is displayed
Display a message box (with mbInformation, MB_OK) in case of downgrade and exit
This works in UI mode - installer exits. However, in /Silent mode, it shows the message box but goes ahead after clicking the Ok button.
Can you please suggest how to achieve similar functionality in silent mode (i.e. gracefully exit the setup)
There's no difference in a the silent mode for implementing prerequisites check. Just test your prerequisites in the InitializeSetup event function, and return False, if you want to stop the installation.
The only things to consider for silent installations are:
Using the SuppressibleMsgBox function for error messages, instead of the plain MsgBox. This way the message can be suppressed with the /suppressmsgboxes command-line switch.
Do not display the message box at all for very silent installations (/verysilent).
See also How to detect whether the setup runs in very silent mode?
function WizardVerySilent: Boolean;
var
i: Integer;
begin
Result := False;
for i := 1 to ParamCount do
if CompareText(ParamStr(i), '/verysilent') = 0 then
begin
Result := True;
Break;
end;
end;
function InitializeSetup(): Boolean;
var
Message: string;
begin
Result := True;
if IsDowngrade then
begin
Message := 'Downgrade detected, aborting installation';
if not WizardVerySilent then
begin
SuppressibleMsgBox(Message, mbError, MB_OK, IDOK);
end
else
begin
Log(Message);
end;
Result := False;
end;
end;
I'm using the code from:
http://www.jrsoftware.org/ishelp/index.php?topic=setup_disablereadypage
It should change the Next button caption to Install when the "Ready" page is disabled using DisableReadyPage directive.
[Setup]
DisableReadyPage=yes
[Code]
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectProgramGroup then
WizardForm.NextButton.Caption := SetupMessage(msgButtonInstall)
else
WizardForm.NextButton.Caption := SetupMessage(msgButtonNext);
end;
But it does not change Next button caption.
As the description of the code says:
For example, if the new last pre-installation wizard page is the Select Program Group page: ...
In your case the last pre-installation page is not Select Program Group page. It's the Select Destination Location page. Probably because you have DisableProgramGroupPage set to no, or you have set it to auto and you are upgrading (the application is installed already).
If you have the DisableProgramGroupPage set to no, the solution is simple, as the Select Destination Location page is always the last. Just replace the wpSelectProgramGroup with wpSelectDir.
[Code]
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectDir then
WizardForm.NextButton.Caption := SetupMessage(msgButtonInstall)
else
WizardForm.NextButton.Caption := SetupMessage(msgButtonNext);
end;
With auto (the default), you do not get any of Select Program Group and Select Destination Location on upgrade, but you get the Ready to Install even with DisableProgramGroupPage (as there would not be any other page before installation). You can use that fact to use Install both for Select Program Group page (for fresh installs) and Ready to Install (for upgrades).
Another issue with their code is that you should get a Finish button on the "Finished" page (wpFinished). What their code does not care for.
The complete solution is:
procedure CurPageChanged(CurPageID: Integer);
begin
// On fresh install the last pre-install page is "Select Program Group".
// On upgrade the last pre-install page is "Read to Install"
// (forced even with DisableReadyPage)
if (CurPageID = wpSelectProgramGroup) or (CurPageID = wpReady) then
WizardForm.NextButton.Caption := SetupMessage(msgButtonInstall)
// On the Finished page, use "Finish" caption.
else if (CurPageID = wpFinished) then
WizardForm.NextButton.Caption := SetupMessage(msgButtonFinish)
// On all other pages, use "Next" caption.
else
WizardForm.NextButton.Caption := SetupMessage(msgButtonNext);
end;
Had you have other pages, like Tasks page, you would have to alter the code accordingly.
Your screenshot shows the wpSelectDir page while in your code you change the button of the wpSelectProgramGroup page.
Is it possible to disable the the Preparing To Install wpPreparing and the Installing wpInstalling Wizard Pages (i.e. the ones with the progress bar) so that they do not show during installation? There does not appear to be a built-in directive or method (e.g. for the Ready Wizard Page you can use DisableReadyPage=yes to do so). Am I missing something, or is it, as I suspect, simply not possible?
I have already tried using:
function ShouldSkipPage(CurPageID: Integer): Boolean;
begin
if CurPageID = wpPreparing then
Result := True;
if CurPageID = wpInstalling then
Result := True;
end;
Have you tried this - DisableReadyPage=yes in the [Setup] section.
Seems the only other option is to use the "install silently" command line switch. I'd be careful though this essentially installs a potentially destructive program without the users knowledge.
It is not possible to skip the wpPreparing or wpInstalling Wizard Pages. However, if the installer is not actually installing anything and is being used to return something, say an unlock code, as is the use case here, the following could be done instead:
//Disable the Exit confirmation prompt
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
Cancel := True;
Confirm := False;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
//Get the unlock code
if CurPageID = UnlockCodePage.ID then
begin
if UnlockCodePage.Values[0] = '' then
begin
MsgBox('You must enter an installation ID to generate an unlock code.',
mbError, MB_OK);
end
else
begin
UnlockCodePage.Values[1] := GetUnlockCode;
end;
Result := False;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
//Define button visibility, whether the Back button is enabled and change the Next and Cancel button labels
WizardForm.CancelButton.Caption := '&Close';
if CurPageID = UnlockCodePage.ID then
begin
WizardForm.BackButton.Enabled := False;
WizardForm.NextButton.Caption := '&Generate';
end;
end;
Hopefully this may help someone looking to do something similar.
so i am currently trying to modify the setup script,
What i was trying to do was after installing i enter in a custom page, this custom page executes 2 scritps(one for creating the database and the other for creating the tables).
while this is executing i want to display a custom label,and a continuous progress bar.
When the execution finish, i want to go directly to the finish page.
I wanto to also remove the next button.
Is this possible?
For the moment i have the custom page with a constinuous progress bar, this page appears after install.i will then add the label after finishing the progress bar part.
here is my code:
[CODE]
var
Page: TWizardPage;
ProgressBar3: TNewProgressBar;
procedure CreateTheWizardPages;
begin
Page := CreateCustomPage(wpInstalling, 'Base de dados', 'A verificar a base de dados');
ProgressBar3 := TNewProgressBar.Create(Page);
ProgressBar3.Left := 5;
ProgressBar3.Width := Page.SurfaceWidth - 5;
ProgressBar3.Parent := Page.Surface;
ProgressBar3.Style := npbstMarquee;
end;
procedure InitializeWizard();
begin
CreateTheWizardPages;
end;
//check the current page,if page equals to wpSelectCompnets, then we add the method on choose to the combobox fo types of installation
procedure CurPageChanged(CurPageID: Integer);
begin
//msgbox(IntToStr( CurPageID),mbInformation, MB_OK);
if CurPageID = wpSelectComponents then
begin
comboboxTypesInstalacao:=WizardForm.TypesCombo;
WizardForm.TypesCombo.OnChange:=#ComboBoxChange;
end
else if CurPageID = Page.ID then
begin
try
CreateDBAndTables('idontimedb.des');
finally
//close this custom wizard page and go to finish page
end;
end;
end;
Thanks in advance.
I try to making setup file to patch previous program. The setup must be able to check if previous program is installed or not.
This is my unusable code
[Code]
function GetHKLM() : Integer;
begin
if IsWin64 then
begin
Result := HKLM64;
end
else
begin
Result := HKEY_LOCAL_MACHINE;
end;
end;
function InitializeSetup(): Boolean;
var
V: string;
begin
if RegKeyExists(GetHKLM(), 'SOFTWARE\ABC\Option\Settings')
then
MsgBox('please install ABC first!!',mbError,MB_OK);
end;
My condition is
must check windows 32- or 64-bits in for RegKeyExists
if previous program is not installed, show error message and exit setup program, else continue process.
How to modify the code?
Thank you in advance.
**Update for fix Wow6432Node problem. I try to modify my code
[Code]
function InitializeSetup: Boolean;
begin
// allow the setup to continue initially
Result := True;
// if the registry key based on current OS bitness doesn't exist, then...
if IsWin64 then
begin
if not RegKeyExists(HKLM, 'SOFTWARE\Wow6432Node\ABC\Option\Settings') then
begin
// return False to prevent installation to continue
Result := False;
// and display a message box
MsgBox('please install ABC first!!', mbError, MB_OK);
end
else
if not RegKeyExists(HKLM, 'SOFTWARE\ABC\Option\Settings' then
begin
// return False to prevent installation to continue
Result := False;
// and display a message box
MsgBox('please install ABC first!!', mbError, MB_OK);
end
end;
end;
The updated code in the question is incorrect -- you should never ever use Wow6432Node anywhere other than when looking at paths in RegEdit.
From the behaviour you have described, you are actually looking for a 32-bit application. In this case you can use the same code regardless of whether Windows is 32-bit or 64-bit; you were overthinking your original question.
Here is the corrected code from your updated question:
[Code]
function InitializeSetup: Boolean;
begin
// allow the setup to continue initially
Result := True;
if not RegKeyExists(HKLM, 'SOFTWARE\ABC\Option\Settings') then
begin
// return False to prevent installation to continue
Result := False;
// and display a message box
MsgBox('please install ABC first!!', mbError, MB_OK);
end;
end;