I am new to Inno Setup and having difficulty find this answer...
I have included a DirectX9 setup file in the installer, but I want to display a MessageBox to the user to ask "Do you want to install DirectX9?" that is done before the regular installation of my game... if he says yes, then I want to run this additional file that I included, but otherwise just proceed to install the game.
The following code will run just before the installation begins. It asks for confirmation from the user and then runs "InstallDirectX.exe" (which must be available to the installer).
[Code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
ResultCode: integer;
begin
if (msgbox('Do you want to install DirectX ?', mbConfirmation, MB_YESNO) = IDYES) then
begin
if Exec(ExpandConstant('InstallDirectX.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// handle success if necessary; ResultCode contains the exit code
MsgBox('Everything is proceeding according to plan', mbInformation, MB_OK);
end
else
begin
// handle failure if necessary; ResultCode contains the error code
MsgBox('Something went horribly wrong', mbError, MB_OK);
end;
end;
end;
If you want to display message box when installation finished, you can use this code:
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
ResultCode: Integer;
begin
if CurStep = ssPostInstall then
begin
if (msgbox('Do you want to install DirectX ?', mbConfirmation, MB_YESNO) = IDYES) then
begin
if Exec(ExpandConstant('{src}\dxwebsetup.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
MsgBox('Installing DirectX completed', mbInformation, MB_OK);
end
else
begin
MsgBox('Installing Error', mbError, MB_OK);
end;
end;
end;
end;
Related
I had an issue on someone’s computer yesterday where my installer did not complete as expected. I connected to their PC to investigate.
It had to do with the VC Redist files. My installer detects if these are needed and if required, downloads and installs them.
I use the command line switches so that the user is not prompted at all and the I use the /norestart flag as my installer has to complete.
The problem was that VC Redist needed them to restart the PC. I found this out by running my installer, it downloaded the Redist setup and attempted to install. My setup aborted. So I tried to manually run the VC Redist Setup and that is where I saw it say the pc needed a reboot.
So, how can I either test if the Redist requires a pc restart and then get my installer to convey this to the user, or, how can I just prompt the user to user if either of the VC Redist setups had been spawned?
I did find this:
https://johnkoerner.com/install/windows-installer-error-codes/
And I noticed the last entry:
ERROR_SUCCESS_REBOOT_REQUIRED 3010
A restart is required to complete the install. This message is
indicative of a success. This does not include installs where the
ForceReboot action is run.
0xBC2 0x80070BC2
This is how I spawn the installers at the moment:
procedure CurStepChanged(CurStep: TSetupStep);
var
ResultCode: integer;
strLogFilePathName, strLogFileName, strNewFilePathName: string;
begin
if (CurStep = ssDone) then
begin
strLogFilePathName := ExpandConstant('{log}');
strLogFileName := ExtractFileName(strLogFilePathName);
strNewFilePathName := ExpandConstant('{#CommonDataDir}\Installation Logs\') + strLogFileName;
FileCopy(strLogFilePathName, strNewFilePathName, false);
end
else if (CurStep = ssPostInstall) then
begin
if (dotNetNeeded) then
begin
(* See here for command line switches:
https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ee942965(v=vs.100)
Do I use passive or showfinalerror? *)
if Exec(ExpandConstant(dotnetRedistPath), '/passive', '',
SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
{ handle success if necessary; ResultCode contains the exit code }
if not (ResultCode = 0) then begin
(* Microsoft present an array of options for this. But since
The interface was visible I think it is safe to just say
that the installation was not completed. *)
MsgBox(ExpandConstant('{cm:InstallFailed,Microsoft .NET Framework 4.6.2}'), mbInformation, MB_OK);
Abort();
end;
end
else begin
{ The execution failed for some reason }
MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
Abort();
end;
end;
if (bVcRedist64BitNeeded) then
begin
if Exec(ExpandConstant(vcRedist64BitPath), '/install /passive /norestart', '',
SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
{ handle success if necessary; ResultCode contains the exit code }
if not (ResultCode = 0) then begin
MsgBox(ExpandConstant('{cm:InstallFailed,Visual Studio x64 Redistributable}'), mbInformation, MB_OK);
Abort();
end;
end
else begin
{ The execution failed for some reason }
MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
Abort();
end;
end;
if (bVcRedist32BitNeeded) then
begin
if Exec(ExpandConstant(vcRedist32BitPath), '/install /passive /norestart', '',
SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
{ Handle success if necessary; ResultCode contains the exit code }
if not (ResultCode = 0) then begin
MsgBox(ExpandConstant('{cm:InstallFailed,Visual Studio x86 Redistributable}'), mbInformation, MB_OK);
Abort();
end;
end
else begin
{ The execution failed for some reason }
MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
Abort();
end;
end;
end;
end;
How do I run an application I have downloaded over the Internet, in the code section using, and also wait for that application to finish running. I have, using InnoTools downloader, downloaded these two files and I want to, after the second one is done downloading to run that download, or jdk-8u111-windows-x64.exe, then continue the installation.
[Code]
procedure InitializeWizard();
begin
ITD_Init;
ITD_AddFile('http://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.0.M13/bin/apache-tomcat-9.0.0.M13-windows-x64.zip', expandconstant('{tmp}\apache-tomcat-9.0.0.M13-windows-x64.zip'));
ITD_DownloadAfter(1);
ITD_AddFile('http://files.downloadnow-1.com/s/software/15/62/36/39/jdk-8u111-windows-x64.exe?token=1479511171_b51e94edd4e002c94fd60a570a7dd270&fileName=jdk-8u111-windows-x64.exe',expandconstant('{tmp}\jdk-8u111-windows-x64.exe'));
ITD_DownloadAfter(2);
end;
Use other download plugin, not ITD (see below for reasons).
Inno Setup 6.1 supports downloads natively. See Inno Setup: Install file from Internet
If you are stuck with an older version of Inno Setup, use the Inno Download Plugin.
When you include idp.iss, it defines a global IDPForm structure. Its Page field is the TWizardPage, representing a download page. Use its ID in the NextButtonClick to run the downloaded file, once the download finishes (the "Next" button on the download page is "pressed" automatically):
#include <idp.iss>
[Code]
procedure InitializeWizard;
begin
idpAddFile(
'https://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.0.M13/bin/' +
'apache-tomcat-9.0.0.M13-windows-x64.zip',
ExpandConstant('{tmp}\apache-tomcat-9.0.0.M13-windows-x64.zip'));
idpAddFile(
'https://www.example.com/jdk-8u111-windows-x64.exe',
ExpandConstant('{tmp}\jdk-8u111-windows-x64.exe'));
idpDownloadAfter(wpSelectDir);
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
FileName: string;
begin
if CurPageID = IDPForm.Page.ID then
begin
FileName := ExpandConstant('{tmp}\jdk-8u111-windows-x64.exe');
Result := Exec(FileName, '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
if not Result then
begin
MsgBox('Cannot execute sub-installer', mbError, MB_OK);
end
else
begin
Result := (ResultCode = 0);
if not Result then
begin
MsgBox('Sub-installer failed', mbError, MB_OK);
end
end;
end
else
begin
Result := True;
end;
end;
There's also DwinsHs (Downloader for Inno Setup).
While you can implement the same using InnoTools Downloader, you should avoid it:
It's outdated and not maintained anymore;
Does not support Unicode Inno Setup (do not use Ansi Inno Setup for new projects);
Does not support HTTPS;
Its download page does not scale on high DPI.
Anyway, for completeness: the ITD_DownloadAfter returns TWizardPage, representing a download page. Use its ID in the NextButtonClick to run the downloaded file, once the download finishes (the "Next" button on the download page is "pressed" automatically):
var
DownloadPage: TWizardPage;
procedure InitializeWizard();
begin
ITD_Init;
ITD_AddFile(
'http://www.example.com/jdk-8u111-windows-x64.exe',
ExpandConstant('{tmp}\jdk-8u111-windows-x64.exe'));
DownloadPage := ITD_DownloadAfter(wpSelectDir);
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
begin
if CurPageID = DownloadPage.ID then
begin
Result :=
Exec(
ExpandConstant('{tmp}\jdk-8u111-windows-x64.exe'),
'', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
if not Result then
begin
MsgBox('Cannot execute sub-installer', mbError, MB_OK);
end
else
begin
Result := (ResultCode = 0);
if not Result then
begin
MsgBox('Sub-installer failed', mbError, MB_OK);
end
end;
end
else
begin
Result := True;
end;
end;
Inno Setup Compiler: How to auto start the default browser with given url? is not what I am wanting for. How / what code in Inno Setup when I want my setup.exe that if it's closed / finished / uninstalled, it will go to a certain site.
To open a web browser from a Pascal Script use a function like this:
procedure OpenBrowser(Url: string);
var
ErrorCode: Integer;
begin
ShellExec('open', Url, '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;
To trigger it, when installer closes, you can use the CurStepChanged(ssDone) event:
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssDone then
begin
OpenBrowser('https://www.example.com/');
end;
end;
Similarly for an uninstaller, use the CurUninstallStepChanged(usDone) event:
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usDone then
begin
OpenBrowser('https://www.example.com/');
end;
end;
My Inno Setup script is used to install a driver. It runs my InstallDriver.exe after this file was copied during step ssInstall.
I need to ask the user to restart in some cases according to the value returned by InstallDriver.exe.
This means that I cannot put InstallDriver.exe in section [Run] because there's no way to monitor it's return value.
So I put it in function CurStepChanged() as follows:
procedure CurStepChanged(CurStep: TSetupStep);
var
TmpFileName, ExecStdout, msg: string;
ResultCode: Integer;
begin
if (CurStep=ssPostInstall) then
begin
Log('CurStepChanged(ssPostInstall)');
TmpFileName := ExpandConstant('{app}') + '\InstallDriver.exe';
if Exec(TmpFileName, 'I', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then .......
However, I can't find a way to make my script restart at this stage.
I thought of using function NeedRestart() to monitor the output of the driver installer, but it is called earlier in the process.
Does it make sense to call the driver installer from within NeedRestart()?
NeedRestart does not look like the right place to install anything. But it would work, as it's fortunately called only once. You will probably want to present a progress somehow though, as the wizard form is almost empty during a call to NeedRestart.
An alternative is to use AfterInstall parameter of the InstallDriver.exe or the driver binary itself (whichever is installed later).
#define InstallDriverName "InstallDriver.exe"
[Files]
Source: "driver.sys"; DestDir: ".."
Source: "{#InstallDriverName}"; DestDir: "{app}"; AfterInstall: InstallDriver
[Code]
var
NeedRestartFlag: Boolean;
const
NeedRestartResultCode = 1;
procedure InstallDriver();
var
InstallDriverPath: string;
ResultCode: Integer;
begin
Log('Installing driver');
InstallDriverPath := ExpandConstant('{app}') + '\{#InstallDriverName}';
if not Exec(InstallDriverPath, 'I', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
Log('Failed to execute driver installation');
end
else
begin
Log(Format('Driver installation finished with code %d', [ResultCode]))
if ResultCode = NeedRestartResultCode then
begin
Log('Need to restart to finish driver installation');
NeedRestartFlag := True;
end;
end;
end;
function NeedRestart(): Boolean;
begin
if NeedRestartFlag then
begin
Log('Need restart');
Result := True;
end
else
begin
Log('Do not need restart');
Result := False;
end;
end;
I test my software with new code.
const MY_EXPIRY_DATE_STR = '20131112'; //Date format: yyyymmdd
function InitializeSetup(): Boolean;
var
ErrorCode: Integer;
begin
//If current date exceeds MY_EXPIRY_DATE_STR then return false and exit Installer.
result := CompareStr(GetDateTimeString('yyyymmdd', #0,#0), MY_EXPIRY_DATE_STR) <= 0;
if not result then
begin
MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
end
if (MsgBox('Autocad will compulsory closed,so please save your drawings and then press OK', mbConfirmation, MB_OK) = IDOK) then
begin
ShellExec('open', 'taskkill.exe', '/f /im acad.exe','', SW_HIDE, ewNoWait, ErrorCode);
ShellExec('open', 'tskill.exe', ' ACAD', '', SW_HIDE, ewNoWait, ErrorCode);
Result := True;
end
else
begin
Result := False;
end;
end;
The issue is the setup show the error message (Now it's forbidden to install this program) but it continue install. I want it exit the installer.
You're forgetting to return from the function when your expiry condition is met.
This
if not result then
begin
MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
end
should be:
if not Result then
begin
MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
Exit;
end;
Without the Exit, the following statements execute with the possibility of setting Result to 'True' again.
Notice also the formatting. If you had it right, there is a good chance that you wouldn't be asking this question.