Inno Setup: Ask for reboot after uninstall - inno-setup

I would like to ask the user to reboot the system, after the application has been uninstalled.
By using AlwaysRestart=yes the user gets only asked after the installation, but the prompt doesn't appear afterwards.
I am using Inno Setup to solve this.
Thank you.

Use UninstallNeedRestart event function:
function UninstallNeedRestart(): Boolean;
begin
Result := True;
end;
It makes uninstaller ask for reboot at the end.
Note that you cannot combine this with the AlwaysRestart directive.

Related

Change default option for restart (if it is needed)

In Inno Setup based installer, is there a way to change the default selection for the restart option shown on the Finish page if restart is needed ? Please note that I am not asking about how to make the installer never ask for a reboot.
Currently, the restart option shows up with "Yes, restart the computer now" as the default selection and some users of the installer have raised a concern that if they are in a haste, they end up clicking on "Finish" button, thus causing the restart to happen.
I see a similar question here.
Similarly, the restart message box shown on uninstalling comes up with default set to "Yes" button. Is there a way to change that too?
Just select the NoRadio instead of the default YesRadio:
procedure InitializeWizard();
begin
WizardForm.NoRadio.Checked := True;
end;
You cannot change, what button is focused by default on the restart prompt in uninstaller.

How to disable "browse" button on defaultDirectory wizard page

I want to show the user to wich directory the program will be installed. But I do not want to allow him to change that directory. So I thought about disabling the "browse" button and greying the field where you can type a path (disabling anyone from typing in there).
I have read this question, which is about preventing the user to select a wrong directory. In a comment by TLama I saw this:
Wouldn't be the Next button is greyed until the user chooses the right folder quite misleading ? What if I as the user forget the right directory ? Wouldn't be better to disable the choose folder edit box or skip that page at all ?
But the User asking the Question did not want to do it the suggested way so there is no further hint for this solution. Could you please tell me how to do this?
(Note: Sorry for opening a new question on such a similar topic, but as a new user I can't see another way of asking for help)
You can disable the directory edit box with the browse button this way:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
procedure InitializeWizard;
begin
WizardForm.DirEdit.Enabled := False;
WizardForm.DirBrowseButton.Enabled := False;
end;

Shared Shortcuts/Icons

I have several inno setups with shared files. With the 'Sharedfile' flag a can make sure that the they only get uninstalled if they're no longer used.
However this is not working for shortcuts or icons as they are called in inno pointing to those files. shortcuts are always getting removed even if the target file is not getting uninstalled.
So is there something i'm missing? a flag for shortcuts?
or do you have some starting point on how to prevent this in code?
Thanks a lot
Thanks alot TLama this seems to be working:
I prevent my shard icons from being uninstalled with the 'uninsneveruninstall' flag.
Then in pascal, check if the file still exists if not manually delete the shortcut or folder:
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usPostUninstall then
begin
if (not(FileExists(ExpandConstant('{app}\executable1.exe')))) then DelTree(ExpandConstant('{group}\myfolder'), True, True, True);
if (not(FileExists(ExpandConstant('{app}\executable2.exe')))) then DeleteFile(ExpandConstant('{group}\myShortcut.lnk');
end;
end;
Personally i think that inno setup should do this by default, checking if the installed shortcuts target is reference counted and use this value for the shortcut.
But anyhow thank you all very much and have a nice day.

Prompting to install DirectX in an Inno installer

I am creating and installer for a game using Inno setup and I want to prompt the user and ask them if they want to install DirectX9 (I already have the full installation directx files in a subfolder) and then to install it for them if they say yes or no... I am not sure how to do this and have limited programming knowledge. Please help!
Use this code to show message box with question and Yes/No buttons:
// Ask the user a Yes/No question
if MsgBox('Are you sure?', mbConfirmation, MB_YESNO) = IDYES then
begin
// User clicked Yes
// Install the DirectX now... (see below)
end;
And this code to execute (launch) DXSETUP.exe
var
ResultCode: Integer;
// Launch DXSETUP and wait for it to terminate
Exec('DXSETUP.exe', '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
I think you need to pack your DirectX files into your installer and extract it to {tmp} directory - or you may run it from CD/DVD (as in example).
See this question for advanced DXSETUP: How to install DirectX redistributable from Inno-setup?
If you need to detect DX version check this: http://www.vincenzo.net/isxkb/index.php?title=DirectX_-_How_to_detect_DirectX_version
You can use a [Tasks] entry to display a checkbox on one of the wizard pages prompting them whether to install/upgrade DX or not (and you can choose whether you want this to be ticked or unticked by default).
For the actual installation, the simplest option is to use a [Run] entry with Tasks: parameter linked to the [Tasks] entry you created; but bear in mind that this will install after your game and you won't be able to catch any errors it might raise. (This is usually not a problem for this sort of thing though.)
The other option is to use the PrepareToInstall event function in [Code]; for this you will need to use ExtractTemporaryFile and Exec. This will install it before your game, and lets you check the exit code to handle errors and reboot requests if need be. See the example script included with Inno for more details, but this is probably more complex than you need for a DX install.
You will also need to decide whether you want to bundle the web-installer or the full-installer for DX. The former is smaller but will require Internet access at install time; the latter will make your installer larger but will not require Internet access. If you are installing from a DVD then the latter is the best option (and you could run it directly from {src} instead of bundling it in [Files] in that case).

Cancelling an InnoSetup installer

Situation
During the installation of our product I detect if our programs are still running (from a previous installation) by using CheckForMutexes. If our programs are still running I pop up a message box (by using MsgBox) that tells the user to close the programs. If the user clicks the ok and they haven't closed our programs, the same message box is displayed. I'd like to display a cancel button in the MsgBox that aborts the installation, which would be desired in the case the user doesn't want to close the running programs.
Question
How can I abort an InnoSetup install programmatically?
Thanks in advance
Take a look at InitializeSetup and Abort in the Inno Setup help. The Abort function will allow the setup to exit.
Call the WizardForm.Close() method.
It will prompt the user if she really wants to cancel the installation.
procedure ExitSetup;
begin
WizardForm.Close;
end;

Resources