2

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;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Roger Federer
  • 329
  • 2
  • 6
  • 12

1 Answers1

4

Inno Setup 6.1 supports downloads natively. See Install file from Internet in Inno Setup.


If you are stuck with an older version of Inno Setup, use the Inno Download Plugin (IDP), not ITD (see below for reasons).

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;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992