How to check your internet connection using Inno Setup

I am studying Inno Setup to make a simple installer. I need to download the file from the website during installation, so it is important to check if there is an Internet connection. How can I check or accept any warning to connect to the Internet during the installation process?

Thank!

+4
source share
1 answer

The best test is trying to upload a file.

"" , . , "". "", . .


.

Inno Setup :

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;
+3

Source: https://habr.com/ru/post/1653432/


All Articles