There are many ways how to get a file from the Internet in InnoSetup. You can use an external library like for instance InnoTools Downloader
, write your own library, or use one of the Windows COM objects. In the following example I've used the WinHttpRequest
COM object for file receiving.
The DownloadFile
function in this script returns True, when the WinHTTP functions doesn't raise any exception, False otherwise. The response content of the HTTP GET request to an URL, specified by the AURL
parameter is then passed to a declared AResponse
parameter. When the script fails the run on exception, AResponse
parameter will contain the exception error message:
[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;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…