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

发布于 2024-09-16 23:14:14 字数 44 浏览 0 评论 0原文

有人知道如何在 INNO Script 中安装之前安装 .NET 框架吗?

Any one have an idea of how to install .NET framework before the setup in INNO Script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光是把杀猪刀 2024-09-23 23:14:14

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

ps 我知道这个问题相当老了,但是这个项目应该是答案的一部分...

[编辑@jitbit]:CodeProject 文章的最新来源可以在这里找到:https://github.com/stfx/innodependencyinstaller

here is a complete solution for all .Net versions and additional software:
CodeProject

p.s. I know this question is rather old, but this project should be part of the answers...

[EDIT by @jitbit]: The latest source for the CodeProject article can be found here: https://github.com/stfx/innodependencyinstaller

樱娆 2024-09-23 23:14:14

您可以使用[Run]部分启动可执行的。可再发行的 .NET 安装程序是可执行文件。例如,您可以下载.NET 2.0 的安装程序位于此处

另请参阅 Inno 安装文档

You can use a [Run] section to launch an executable. The redistributable .NET installer is an executable. For example, you can download the installer for .NET 2.0 here.

See also the Inno Setup documentation.

挽心 2024-09-23 23:14:14

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

另外,请记住,某些 .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;

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

here is a possible solution, inside InitializeWizard() method you check on the registry for the specific version of the .net framework that you need, if it is not present, then you can include, as a part of your inno installer, the framework web installer, and you can execute it, and wait for it to conclude, and depending on whether it was successfully installed or not, you may choose to continue or to abort the install.

Also, have in mind that some .net framework installers may require a reboot after installation, in that case, you also may want to include a key on the registry, under the run-once or run keys, so your installer gets called after the reboot (in case the user has chosen to reboot immediately after install).

Here is an example of this:

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;

I think you would still need to find a way to get the path of the executing installer, if you want to set the key on the registry, but aside of that, I think this code can help you with your question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文