Wednesday, April 25, 2012

Making a Web Request within Inno Setup

Inno Setup is a very easy to use installer for Windows Software. We use it to package and deploy our ASP.NET code, releases, automatically download releases from our website, determine required patches, configure the web.config files etc. A lot of this is achieved by integrating VB Scripts inside the installer instead of writing script code inside Inno Setup. However I recently had a requirement where an external ASMX web service needed to be invoked to encrypt a password entered by the user before it. This could be achieved by using a vb script and invoke that inside the installer but using the Windows WinHTTP inside InnoSetup was fairly easy and this was the first time I directly used COM inside Inno Setup. Here is the code:

WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');

WinHttpReq.Open('GET', MYURL, false);

if WinHttpReq.Status <> 200 then begin

MsgBox('Could not run service to get encrypted password.', mbError, MB_OK);
end else
//MsgBox('SUCCESS', mbInformation, MB_OK);
if Length(WinHttpReq.ResponseText) > 0 then begin
index2 := Pos('', WinHttpReq.ResponseText); index1 := Pos('', WinHttpReq.ResponseText) + Length(''); 
EncrPasswd := Copy(WinHttpReq.ResponseText,index1,index2-index1);

1 comment:

Anonymous said...

Great code, thank you for sharing!