谁知道如何在INNO脚本中安装之前安装.NET框架?
发布于 2013-01-23 16:44:21
以下是适用于所有.Net版本和附加软件的完整解决方案:CodeProject
附注:我知道这个问题有点老了,但这个项目应该是答案的一部分……
由@jitbit编辑:可以在这里找到CodeProject文章的最新源代码:https://github.com/stfx/innodependencyinstaller
发布于 2010-09-01 05:53:16
你可以通过use a [Run] section来启动一个可执行文件。可再发行的.NET安装程序是一个可执行文件。例如,您可以使用download the installer for .NET 2.0 here。
另请参阅Inno Setup documentation。
发布于 2010-09-08 05:37:43
这是一个可能的解决方案,在InitializeWizard()方法中,您可以在注册表中检查您需要的特定版本的.net框架,如果它不存在,那么您可以将框架web安装程序包含在您的inno安装程序中,您可以执行它,并等待它结束,并且根据它是否成功安装,您可以选择继续安装或中止安装。
此外,请记住,一些.net框架安装程序可能需要在安装后重新启动,在这种情况下,您可能还希望在注册表中的run-once或run键下包含一个键,以便在重新启动后调用您的安装程序(以防用户选择在安装后立即重新启动)。
下面是一个这样的例子:
function CheckIfFrameworkNeeded(): Boolean;
var
VersionFrameWork: Cardinal;
FrameWorkNeeded: Boolean;
begin
FrameWorkNeeded := true;
//**********************************************************************
// Check Fot Framewok 3.5.
//**********************************************************************
if (RegQueryDWordValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v3.5', 'Install', VersionFrameWork)) then
begin
if (VersionFrameWork = 1) then
FrameWorkNeeded := false
end;
Result := FrameWorkNeeded;
end;
function Install_NETFramework() : Integer;
var
hWnd: Integer;
ResultCode: Integer;
dotnetRedistPath: string;
outVar : string;
begin
dotnetRedistPath:= ExpandConstant('{tmp}\dotnetfx35setup.exe');
//*********************************************************************************
// Run the install file for .NET Framework 3.5. This is usually dotnetfx35setup.exe from MS
//***********************************************************************************
if Exec(ExpandConstant(dotnetRedistPath), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// ResultCode contains the exit code
case ResultCode of
// 1641 The requested operation completed successfully. The system will be restarted so the changes can take effect.
// 3010 The requested operation is successful. Changes will not be effective until the system is rebooted.
1641:
begin
Result := 1;
end
3010, 0:
begin
Result := 0;
end else // -> case default
begin
Result := -1;
end
end;
end else
begin
//handle failure if necessary; ResultCode contains the error code
Result := -1;
end;
end;
procedure InitializeWizard();
var
frameworkNeeded: Boolean;
installerPath: String;
res: integer;
begin
frameworkNeeded := CheckIfFrameworkNeeded();
if (frameworkNeeded = true)then
begin
if MsgBox('This setup requires the .NET Framework 3.5.'#13 + 'The .NET Framework can be obtained from the web.'#13 + 'Would you like to do this now?', mbConfirmation, MB_YESNO) = IDYES then
begin
// register in the registry the path to your current installer, so it gets called after a reboot
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'MyAppKey', installerPath); // installerPath is the path of your installer
res := Install_NETFramework();
case res of
1: // a restart is going to be executed right away so we abort to avoid the reboot from happening
begin
Abort;
end
0: // a restart is going to be executed later
begin
//Delete the key we added before since we don't need it cause we are installing now
RegDeleteValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'MyAppKey');
// continue with your installation here
end
-1: // an error happened
begin
Abort;
end
end;
end else
begin
//The user has chosen not to install the framework
MsgBox('The application can not be installed unless the framework 3.5 be installed first.', mbError, MB_OK);
Abort;
end;
end else
begin
// the framework is present so continue with your installation here
end;
end;我认为如果你想在注册表上设置注册表项,你仍然需要找到一种方法来获取执行安装程序的路径,但除此之外,我认为这段代码可以帮助你解决你的问题。
https://stackoverflow.com/questions/3613461
复制相似问题