Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check Internet connection using Inno Setup

I'm learning about Inno Setup to make a simple installer. I need to download a file from a website during the installation, so it's important check if there is Internet connection. How can I check or take some alert to connect Internet during the process of the installation?

Thanks!

like image 396
Jaime Menendez Llana Avatar asked Sep 02 '16 11:09

Jaime Menendez Llana


People also ask

How do I use Inno installer?

Go to Menu, Project, then Compile to compile and create the setup file. This will create a complete installer. Run the Setup and your application will be installed correctly. Innosetup offers an awesome alternative to create great looking Installers for free.

Can Inno Setup create MSI?

Create MSI with Inno Setup. The MSI Wrapper was produced to create MSI packages from executable files built with Inno Setup. It puts the setup.exe inside an MSI file and runs it with the specified command line switches when the MSI package is installed.

What language is Inno Setup?

It defines two languages: English, based on the standard Default. isl file, and Dutch, based on a third-party translation.

What is Inno Setup compiler?

Inno Setup is a free software script-driven installation system created in Delphi by Jordan Russell. The first version was released in 1997. Inno Setup. Screenshot of the Inno Setup IDE running on Windows 7. Developer(s)


1 Answers

The best check is to try to actually download the file.

"Internet" is hardly a real thing that you can connect to. So it's hard to test, if you are connected to "Internet". You actually do not need a connection to "Internet", you need a connection to your server. So test that.


See also

  • How to check if internet connection is present in java?
  • What is the best way to check for Internet connectivity using .NET?

An equivalent implementation in Inno Setup would be like:

function InitializeSetup(): Boolean;
var
  WinHttpReq: Variant;
  Connected: Boolean;
begin
  Connected := False;
  repeat
    Log('Checking connection to the server');
    try
      WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
      { Use your real server host name }
      WinHttpReq.Open('GET', 'https://www.example.com/', False);
      WinHttpReq.Send('');
      Log('Connected to the server; status: ' + IntToStr(WinHttpReq.Status) + ' ' +
          WinHttpReq.StatusText);
      Connected := True;
    except
      Log('Error connecting to the server: ' + GetExceptionMessage);
      if WizardSilent then
      begin
        Log('Connection to the server is not available, aborting silent installation');
        Result := False;
        Exit;
      end
        else
      if MsgBox('Cannot reach server. Please check your Internet connection.',
                mbError, MB_RETRYCANCEL) = IDRETRY then
      begin
        Log('Retrying');
      end
        else
      begin
        Log('Aborting');
        Result := False;
        Exit;
      end;
    end;
  until Connected;

  Result := True;
end;
like image 126
Martin Prikryl Avatar answered Oct 18 '22 22:10

Martin Prikryl