使用Inno setup在我的应用程序中安装.Net框架

时间:2010-08-31 21:44:48

标签: inno-setup

任何人都知道如何在INNO Script中设置之前安装.NET框架?

3 个答案:

答案 0 :(得分:3)

这是所有.Net版本和其他软件的完整解决方案: CodeProject

P.S。我知道这个问题相当陈旧,但这个项目应该是答案的一部分......

[编辑@jitbit]:CodeProject文章的最新资料来源:https://github.com/stfx/innodependencyinstaller

答案 1 :(得分:2)

您可以use a [Run] section启动可执行文件。可再发行的.NET安装程序是可执行文件。例如,您可以download the installer for .NET 2.0 here

另请参阅Inno Setup documentation

答案 2 :(得分:0)

这是一个可能的解决方案,在InitializeWizard()方法中,您在注册表中检查所需的.net框架的特定版本,如果它不存在,那么您可以包含,作为您的inno安装程序的一部分,框架Web安装程序,您可以执行它,并等待它结束,并根据它是否成功安装,您可以选择继续或中止安装。

另外,请记住,某些.net框架安装程序可能需要在安装后重新启动,在这种情况下,您还可能希望在注册表中包含一个密钥,在运行一次或运行密钥下,以便安装程序获取重启后调用(如果用户选择在安装后立即重启)。

以下是此示例:

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;

我认为你仍然需要找到一种方法来获取正在执行的安装程序的路径,如果你想在注册表中设置密钥,除此之外,我认为这段代码可以帮助你解决问题。 / p>