2012-01-14 97 views

回答

9

如何在InnoSetup中从Internet获取文件有很多种方法。您可以使用外部库,例如InnoTools Downloader,编写自己的库或使用其中一个Windows COM对象。在以下示例中,我使用了文件接收的COM对象WinHttpRequest

此脚本中的DownloadFile函数返回True,当WinHTTP函数不引发任何异常时,否则返回False。然后将HTTP GET请求对URL的响应内容(由AURL参数指定)传递给声明的AResponse参数。当脚本失败上的异常运行,AResponse参数将包含异常错误消息:

[Code] 
function DownloadFile(const AURL: string; var AResponse: string): Boolean; 
var 
    WinHttpRequest: Variant; 
begin 
    Result := True; 
    try 
    WinHttpRequest := CreateOleObject('WinHttp.WinHttpRequest.5.1'); 
    WinHttpRequest.Open('GET', AURL, False); 
    WinHttpRequest.Send; 
    AResponse := WinHttpRequest.ResponseText; 
    except 
    Result := False; 
    AResponse := GetExceptionMessage; 
    end; 
end; 

procedure InitializeWizard; 
var 
    S: string; 
begin 
    if DownloadFile('http://www.example.com/versioninfo.txt', S) then 
    MsgBox(S, mbInformation, MB_OK) 
    else 
    MsgBox(S, mbError, MB_OK) 
end; 
+0

TLama的回答[这里](https://stackoverflow.com/a/22356942/2128797)详细阐述了这一点。 – 2017-06-23 07:29:58