我想分享我编写的实际 Inno Setup 代码,它专门回答了我的问题。感谢先前的答案将我推向正确的方向。
function FindFramework45(): Boolean;
var
bVer4x5: Boolean;
bSuccess: Boolean;
iInstalled: Cardinal;
strVersion: String;
iPos: Cardinal;
begin
Result := False;
bSuccess := RegQueryDWordValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Install', iInstalled);
if (1 = iInstalled) AND (True = bSuccess) then
begin
bSuccess := RegQueryStringValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Version', strVersion);
if (True = bSuccess) then
Begin
iPos := Pos('4.5.', strVersion);
if (0 < iPos) then bVer4x5 := True;
End
end;
if (True = bVer4x5) then begin
Result := True;
end;
end;
NextButtonClick() 事件将在欢迎之后立即调用此函数。
File 和 Run 部分仅包含一个使用 Check 并检查该变量的函数。
[Run]
Filename: "{app}\dotNetFx45_Full_setup.exe"; Parameters: "/q"; StatusMsg: "Installing Microsoft .Net 4.5 Framework..."; Check: InstallFramework45();
[Files]
Source: "{#MySourceBaseDir}\{#MyAppVersion}\{#MyDirBinaries}\dotNetFx45_Full_setup.exe"; Flags: deleteafterinstall; DestDir: "{app}"; Check: InstallFramework45();
我会说很明显,必须确保首先安装 .Net Framework 4.0,然后检查/安装 .Net Framework 4.5。
现在,如果 System.Data.SQLite.org 将推出与 Visual Studio 2012 兼容的版本,我可以检查我的另一个重大升级任务。
更新:2010.10.11(根据 TLana 的评论) 注意:我决定保留原始代码,因为我认为其他人希望看到我从哪里开始。下面的代码是我现在的位置。下面的代码还使用正确的注册表位置并检查 .Net 4.0 和新的 .Net 4.5。未来呢?当 .Net 6.0 和 6.5 出现时,只需将 4 更改为 6,除非 Microsoft 更改公式。.5 升级似乎不是一个新框架,而是对现有框架的升级。
[Files]
Source: "{#MySourceBaseDir}\{#MyDirBinaries}\dotNetFx40_Full_x86_x64.exe"; Flags: deleteafterinstall; DestDir: "{app}"; Check: Framework40IsNotInstalled();
Source: "{#MySourceBaseDir}\{#MyDirBinaries}\dotNetFx45_Full_setup.exe"; Flags: deleteafterinstall; DestDir: "{app}"; Check: Framework45IsNotInstalled();
Source: "{#MySourceBaseDir}\{#MyDirBinaries}\mysql-connector-net-6.5.4.msi"; Flags: deleteafterinstall; DestDir: "{tmp}";
[Run]
Filename: "{app}\vcredist_x86.exe"; Parameters: "/q"; StatusMsg: "Installing Microsoft Visual C++ 2010 Redistributable Package...";
Filename: "{app}\dotNetFx40_Full_x86_x64.exe"; Parameters: "/q"; StatusMsg: "Installing Microsoft .Net 4.0 Full Framework..."; Check: Framework40IsNotInstalled();
Filename: "{app}\dotNetFx45_Full_setup.exe"; Parameters: "/q"; StatusMsg: "Installing Microsoft .Net 4.5 Framework..."; Check: Framework45IsNotInstalled();
Filename: "msiexec"; Parameters: "/package ""{tmp}\mysql-connector-net-6.5.4.msi"" /quiet"; StatusMsg: "Installing MySQL Connector...";
[Code]
function Framework40IsNotInstalled: Boolean;
var
bVer4x0Client: Boolean;
bVer4x0Full: Boolean;
bSuccess: Boolean;
iInstalled: Cardinal;
begin
Result := True;
bVer4x0Client := False;
bVer4x0Full := False;
bSuccess := RegQueryDWordValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v4\Client', 'Install', iInstalled);
if (1 = iInstalled) AND (True = bSuccess) then bVer4x0Client := True;
bSuccess := RegQueryDWordValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Install', iInstalled);
if (1 = iInstalled) AND (True = bSuccess) then bVer4x0Full := True;
if (True = bVer4x0Full) then begin
Result := False;
end;
end;
function Framework45IsNotInstalled: Boolean;
var
bVer4x5: Boolean;
bSuccess: Boolean;
iInstalled: Cardinal;
strVersion: String;
iPos: Cardinal;
begin
Result := True;
bVer4x5 := False;
bSuccess := RegQueryDWordValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Install', iInstalled);
if (1 = iInstalled) AND (True = bSuccess) then
begin
bSuccess := RegQueryStringValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v4\Full', 'Version', strVersion);
if (True = bSuccess) then
Begin
iPos := Pos('4.5.', strVersion);
if (0 < iPos) then bVer4x5 := True;
End
end;
if (True = bVer4x5) then begin
Result := False;
end;
end;