2010-08-31 55 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; 

其中,我認爲這個代碼可以幫助你解決你的問題。

相關問題