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

Inno setup 使用Inno安装程序在我的应用程序中安装.Net framework,inno-setup,Inno Setup,在INNO脚本中进行安装之前,有人知道如何安装.NET framework吗?您可以启动一个可执行文件。可再发行的.NET安装程序是一个可执行文件。例如,你可以 另请参见。这里有一个可能的解决方案,在InitializeWizard()方法中,您可以在注册表中检查所需的.net framework的特定版本,如果它不存在,那么您可以将framework web installer作为inno安装程序的一部分,并执行它,然后等待它结束,根据安装是否成功,您可以选择继续或中止安装 另外,请记住,某些

在INNO脚本中进行安装之前,有人知道如何安装.NET framework吗?

您可以启动一个可执行文件。可再发行的.NET安装程序是一个可执行文件。例如,你可以


另请参见。

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

另外,请记住,某些.net framework安装程序可能需要在安装后重新启动,在这种情况下,您可能还希望在注册表中的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;

如果您想在注册表上设置注册表项,我认为您仍然需要找到获取正在执行的安装程序路径的方法,但除此之外,我认为此代码可以帮助您解决问题。

以下是适用于所有.Net版本和其他软件的完整解决方案:

p、 我知道这个问题很老了,但这个项目应该是答案的一部分


[EDIT by@jitbit]:这里可以找到CodeProject文章的最新来源:

通过使用[run]部分,它总是运行,但我不想每次都运行,我只想在机器中没有.net frame work时运行。+1,@Krish,这就是参数的用途。您可以使用它,例如..另请参见:您可能希望看到此其他问题:该问题显示了一种测试.Net framework是否已安装的方法,如果不是在安装其他文件之前,而是在用户选择通过向导安装之后,则安装。