微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

inno-setup – 如何使用Inno Setup检查Internet连接

我正在学习Inno Setup来制作一个简单的安装程序.我需要在安装过程中从网站下载文件,因此检查是否存在Internet连接非常重要.如何在安装过程中检查或采取一些警报来连接Internet?

谢谢!

解决方法

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

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

也可以看看

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

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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐