【问题标题】:How to check Internet connection using Inno Setup如何使用 Inno Setup 检查 Internet 连接
【发布时间】:2016-09-02 11:24:35
【问题描述】:

我正在学习 Inno Setup 来制作一个简单的安装程序。我需要在安装过程中从网站下载文件,因此检查是否有 Internet 连接很重要。在安装过程中如何检查或提醒连接互联网?

谢谢!

【问题讨论】:

    标签: inno-setup internet-connection


    【解决方案1】:

    最好的检查是尝试实际下载文件。

    “互联网”几乎不是您可以连接的真实事物。所以很难测试,如果你连接到“互联网”。您实际上不需要连接到“Internet”,您需要连接到您的服务器。所以测试一下。


    另见

    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;
    

    【讨论】:

    • 所以,您建议制作例如简单的 Java 或 .NET 脚本来测试 Internet 连接(进行 ping...)并在开始安装之前从 InnoSetup 运行它?
    • 不,我建议您在 Inno Setup Pascal 脚本中实现该逻辑。我在答案中添加了一个示例。
    • 啊好吧!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 1970-01-01
    • 2013-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多