该例子为使用inno setup 打包.net框架的程序,根据.net 的注册表的注册信息 检测该系统是否已经安装了.net的 框架,如果没有安装的情况,执行安装,
安装之前,判断框架文件是否存在,不存在则指定的网址下载该.net的,到系统的临时文件夹里,再执行.net的安装,安装.net的之后才能执行程序的下一步
安装操作
isxdl.dll 下载地址http://www.down-dll.com/dll/i/isxdl.dll.zip
ISS 代码实例
[_ISTool]
EnableISX=true
[Setup]
AppName=MyApp
AppVerName=MyApp 1.0.0
MinVersion=4.1,4.0
DefaultDirName={pf}\MyApp
DefaultGroupName=MyApp
UninstallDisplayIcon={app}\MyApp.exe
Compression=lzma
SolidCompression=true
OutputBaseFilename=MyAppSetup
[Files]
Source: c:\ISSI\include\isxdl\isxdl.dll; Flags: dontcopy
Source: Release\MyApp.exe; DestDir: {app}
[Messages]
WinVersionTooLowError=MyApp requires Windows NT4, Windows 98 or later.
[Icons]
Name: {group}\MyApp; Filename: {app}\MyApp.exe
Name: {group}\Uninstall MyApp; Filename: {uninstallexe}
[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/a/a/c/aac39226-8825-44ce-90e3-bf8203e74006/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\v1.1')) then begin
dotNetNeeded := true;
if (not IsAdminLoggedOn()) then begin
MsgBox('MyApp 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', 'MyApp 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;