Reply
Automatically downloading .NET Framework during installation
Old 03-29-2007, 10:50 AM Automatically downloading .NET Framework during installation
RickPlmr's Avatar
Super Talker

Posts: 107
Name: Rick Palmer
I recently did an internal application deployment to about a dozen users in our IT department, and the application required .NET 2.0. I found that only about 20% of the users had the framework installed on their Windows XP systems, and we had to go out and download .NET for the others.

After that experience, which was a real eye opener, we decided to include a check for the framework in our installation package, and I built a script to automatically download it if it wasn't already installed.

Low user intervention was a key goal, and I suspect that will be the case for most applications. If the user has to jump through a lot of hoops/steps, then they may choose to quit altogether.

I used InnoSetup for the installer, which is free yet very powerful and certainly a production-quality installer. Here's the script I used that automates the download and installation of the .NET 2.0 Framework prior to installing the application. This would be inside a file with a .iss extension (e.g. installer.iss):

[_ISTool]
EnableISX=true

[Files]
Source: C:\Program Files\ISTool\isxdl.dll; Flags: dontcopy

[code]
var
dotnetRedistPath: string;
downloadNeeded: boolean;
dotNetNeeded: boolean;
memoDependenciesNeeded: string;

procedure isxdl_AddFile(URL, Filename: PChar);
external 'isxdl_AddFile@files:isxdl.dll stdcall';
function isxdl_DownloadFiles(hWnd: Integer): Integer;
external 'isxdl_DownloadFiles@files:isxdl.dll stdcall';
function isxdl_SetOption(Option, Value: PChar): Integer;
external 'isxdl_SetOption@files:isxdl.dll stdcall';


const
dotnetRedistURL = 'http://download.microsoft.com/download/5/6/7/567758a3-759e-473e-bf8f-52154438565a/dotnetfx.exe';
// local system for testing...
// dotnetRedistURL = 'http://192.168.1.1/dotnetfx.exe';

function InitializeSetup(): Boolean;

begin
Result := true;
dotNetNeeded := false;

// Check for required netfx installation
if (not RegKeyExists(HKLM, 'Software\Microsoft\.NETFramework\policy\v2.0')) then begin
dotNetNeeded := true;
if (not IsAdminLoggedOn()) then begin
MsgBox('This application needs the Microsoft .NET Framework to be installed by an Administrator', mbInformation, MB_OK);
Result := false;
end else begin
memoDependenciesNeeded := memoDependenciesNeeded + ' .NET Framework' #13;
dotnetRedistPath := ExpandConstant('{src}\dotnetfx.exe');
if not FileExists(dotnetRedistPath) then begin
dotnetRedistPath := ExpandConstant('{tmp}\dotnetfx.exe');
if not FileExists(dotnetRedistPath) then begin
isxdl_AddFile(dotnetRedistURL, dotnetRedistPath);
downloadNeeded := true;
end;
end;
SetIniString('install', 'dotnetRedist', dotnetRedistPath, ExpandConstant('{tmp}\dep.ini'));
end;
end;

end;

function NextButtonClick(CurPage: Integer): Boolean;
var
hWnd: Integer;
ResultCode: Integer;

begin
Result := true;

if CurPage = wpReady then begin

hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));

// don't try to init isxdl if it's not needed because it will error on < ie 3
if downloadNeeded then begin

isxdl_SetOption('label', 'Downloading Microsoft .NET Framework');
isxdl_SetOption('description', 'This application needs to install the Microsoft .NET Framework. Please wait while Setup is downloading extra files to your computer.');
if isxdl_DownloadFiles(hWnd) = 0 then Result := false;
end;
if (Result = true) and (dotNetNeeded = true) then begin
if Exec(ExpandConstant(dotnetRedistPath), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
// handle success if necessary; ResultCode contains the exit code
if not (ResultCode = 0) then begin
Result := false;
end;
end else begin
// handle failure if necessary; ResultCode contains the error code
Result := false;
end;
end;
end;
end;

function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
var
s: string;

begin
if memoDependenciesNeeded <> '' then s := s + 'Dependencies to install:' + NewLine + memoDependenciesNeeded + NewLine;
s := s + MemoDirInfo + NewLine + NewLine;

Result := s
end;
__________________
online-etraining - free online training in Java, J2EE, and MySQL.
rickysays - answers and advice from a geek who knows stuff.
RickPlmr is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-04-2007, 10:31 AM Re: Automatically downloading .NET Framework during installation
WebcyteDesign's Avatar
Extreme Talker

Posts: 159
Location: Hamilton
Wouldn't it be quicker to package the .Net redistributable with the program rather than spending time downloading it? Just a thought. Plus that way they're using the .Net framework it was tested with as well. But very nice job.
WebcyteDesign is offline
Reply With Quote
View Public Profile Visit WebcyteDesign's homepage!
 
Old 04-04-2007, 10:35 AM Re: Automatically downloading .NET Framework during installation
RickPlmr's Avatar
Super Talker

Posts: 107
Name: Rick Palmer
That would make a large download for someone who might already have it installed. This way it checks if you already have it, and only downloads it if you need it.

And assuming the program is being downloaded from the Internet anyway, the total amount of download time would be about the same for someone who doesn't have .NET (they'd either download it bundled with the program, or separately after the script determines they don't have it).
__________________
online-etraining - free online training in Java, J2EE, and MySQL.
rickysays - answers and advice from a geek who knows stuff.
RickPlmr is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Automatically downloading .NET Framework during installation
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13449 seconds with 13 queries