2010-08-31 88 views
3

任何人都有在INNO脚本中安装之前如何安装.NET框架的想法?使用Inno setup与我的应用程序一起安装.Net框架

+0

请参见:CodeProject上的文章最新的源代码可以在这里找到: http://stackoverflow.com/q/4334066/588306 – Deanna 2013-01-23 11:59:16

+0

你可能想看到这个问题:[如何安装.NET框架作为使用InnoSetup的先决条件?](http://stackoverflow.com/q/20752882/204690) 这显示了一种方法来测试.Net框架是否已安装,并且如果不安装*,安装其他文件之前安装它,但在用户选择通过向导安装之后安装它。 – Grhm 2014-02-27 16:37:32

回答

2

您可以use a [Run] section启动一个可执行文件。可重新分发的.NET安装程序是可执行文件。例如,您可以download the installer for .NET 2.0 here。请参阅Inno Setup documentation

+0

通过使用[运行]节它始终运行,但我不想运行时,我只是想在机器中没有.net框架工作时运行。 – Krish 2010-08-31 21:58:32

+3

+1,@Krish,这就是['check'](http://www.jrsoftware.org/ishelp/topic_scriptcheck.htm)参数的用途。您可以使用它,例如['这种方式'](http://stackoverflow.com/a/10111173/960757)。 – TLama 2012-07-29 13:16:55

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; 

其中,我认为这个代码可以帮助你解决你的问题。