【问题标题】:NSIS installer that checks for .NET Framework检查 .NET Framework 的 NSIS 安装程序
【发布时间】:2010-11-29 14:42:32
【问题描述】:

我想创建一个 NSIS 安装程序来检查 .NET Framework 并在它不存在时安装它。你能给我指一个脚本吗?我是 NSIS 的新手。

【问题讨论】:

标签: .net installation nsis


【解决方案1】:

如果您正在寻找 .net 框架 4.0+(及更高版本)的选项,包括

  • .net 4.5
  • .net 4.5.1

检查此插件是否适用于 NSIS:DotNetChecker

【讨论】:

    【解决方案2】:

    我遇到了“DotNET.nsh”插件问题,您可以在某个地方找到它, 并简单地使用了这个解决方案(对于.net 4.0,完全安装 - 我需要, 您也可以将其限制在客户端包中):

    ClearErrors
    ReadRegDWORD $0 HKLM "Software\Microsoft\Net Framework Setup\NDP\v4\Full" "Install"
    IfErrors dotNet40NotFound
    IntCmp $0 1 dotNet40Found
    dotNet40NotFound: 
        Banner::show /set 76 "Installing .NET Framework 4.0" "Please wait"  
        File /nonfatal "tools\dotNetFx40_Full_setup.exe"
        ; if you don't have $TEMP already, add here:
        ; SetOutPath $TEMP
        ExecWait "$TEMP\dotNetFx40_Full_setup.exe /passive /norestart"
        Delete /REBOOTOK "$TEMP\dotNetFx40_Full_setup.exe"
        Banner::destroy
    dotNet40Found:
    

    横幅内容是可选的,你可以使用DetailPrint 或类似的。 这样,您就可以使用 .NET 4.0 的 Web 安装程序,但它非常小 (与没有的 .NET 版本相反)。安装程序进行下载 如果需要,并且您不需要数公里的 NSIS 代码。

    【讨论】:

    • 可能不是投票的正确理由,但这个脚本代码对我来说比其他任何这样做的例子都更有意义。谢谢。
    【解决方案3】:

    试试DotNetVer 脚本。它使用LogicLib,非常好用。

    • HasDotNet 检查是否安装了特定版本的 .NET 框架。 可以替换为以下值:1.0、1.1、2.0、3.0、3.5、4.0。
    • AtLeastDotNetServicePack 检查 .NET 框架是否至少具有指定的服务包版本。
    • IsDotNetServicePack 检查 .NET 框架是否具有完全符合指定的服务包版本。
    • HasDotNetClientProfile 检查 .NET 框架是否是客户端配置文件安装。
    • HasDotNetFullProfile 检查 .NET 框架是否为完整安装。

    示例:

    ${If} ${HasDotNet4.0} DetailPrint "安装了 Microsoft .NET Framework 4.0。" ${If} ${DOTNETVER_4_0} AtLeastDotNetServicePack 1 DetailPrint "Microsoft .NET Framework 4.0 至少为 SP1。" ${其他} DetailPrint "未安装 Microsoft .NET Framework 4.0 SP1。" ${结束如果} ${If} ${DOTNETVER_4_0} HasDotNetClientProfile 1 DetailPrint “Microsoft .NET Framework 4.0(客户端配置文件)可用。” ${结束如果} ${If} ${DOTNETVER_4_0} HasDotNetFullProfile 1 DetailPrint "Microsoft .NET Framework 4.0 (Full Profile) 可用。" ${结束如果} ${If} ${DOTNETVER_4_0} HasDotNetFullProfile 0 DetailPrint “Microsoft .NET Framework 4.0(完整配置文件)不可用。” ${结束如果} ${结束如果}

    【讨论】:

      【解决方案4】:
      ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client" Install
      

      那么你应该检查$0。怎么做就看你自己了。

      【讨论】:

      • 与其他答案相比,您认为这增加了什么?它没有说它应该是什么,也没有安装它。
      【解决方案5】:

      以下代码检查是否安装了 .Net 3.5,如果没有,它将静默安装。它使用一个宏来检查注册表中是否存在指定的键。

      宏:

      # This macro checks if a certain key exists in the registry
      !macro IfKeyExists ROOT MAIN_KEY KEY
          push $R0
          push $R1
      
          !define Index 'Line${__LINE__}'
      
          StrCpy $R1 "0"
      
          "${Index}-Loop:"
          ; Check for Key
          EnumRegKey $R0 ${ROOT} "${MAIN_KEY}" "$R1"
          StrCmp $R0 "" "${Index}-False"
          IntOp $R1 $R1 + 1
          StrCmp $R0 "${KEY}" "${Index}-True" "${Index}-Loop"
      
          "${Index}-True:"
          ;Return 1 if found
          push "1"
          goto "${Index}-End"
      
          "${Index}-False:"
          ;Return 0 if not found
          push "0"
          goto "${Index}-End"
      
          "${Index}-End:"
          !undef Index
          exch 2
          pop $R0
          pop $R1
      !macroend
      

      功能:

      # The function that checks if .net is already installed
      Function CheckDotNet
      !insertmacro IfKeyExists HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall" "{CE2CDD62-0124-36CA-84D3-9F4DCF5C5BD9}"
      Pop $R0
      ${If} $R0 == 0 # not installed NOTE: /q:a means this will be a silent installation
          ExecWait "$EXEDIR\dotnetfx35.exe /q:a"
          Goto endPrerequisites
      ${EndIf}
      
          endPrerequisites:
              # Code to execute after checking/installing (if necessary) .Net 
              # You can just put "Goto +2" here, in order to go to the next section/function
      FunctionEnd
      

      为了让它工作,你必须在 .onInit 函数的某个地方调用 CheckDotNet 并确保 dotnetfx35.exe 包含在你的安装程序中的 $EXEDIR 中(当然你可以更改这些参数随心所欲)。

      对于其他版本的.Net,我想唯一不同的是IfKeyExistsmacro 参数中指定的注册表项(现在是{CE2CDD62-0124-36CA-84D3-9F4DCF5C5BD9}

      【讨论】:

        【解决方案6】:
        !define DOT_MAJOR "2"
        !define DOT_MINOR "0"
        
        Function IsDotNetInstalled
        
          StrCpy $0 "0"
          StrCpy $1 "SOFTWARE\Microsoft\.NETFramework" ;registry entry to look in.
          StrCpy $2 0
        
          StartEnum:
            ;Enumerate the versions installed.
            EnumRegKey $3 HKLM "$1\policy" $2
        
            ;If we don't find any versions installed, it's not here.
            StrCmp $3 "" noDotNet notEmpty
        
            ;We found something.
            notEmpty:
              ;Find out if the RegKey starts with 'v'.  
              ;If it doesn't, goto the next key.
              StrCpy $4 $3 1 0
              StrCmp $4 "v" +1 goNext
              StrCpy $4 $3 1 1
        
              ;It starts with 'v'.  Now check to see how the installed major version
              ;relates to our required major version.
              ;If it's equal check the minor version, if it's greater, 
              ;we found a good RegKey.
              IntCmp $4 ${DOT_MAJOR} +1 goNext yesDotNetReg
              ;Check the minor version.  If it's equal or greater to our requested 
              ;version then we're good.
              StrCpy $4 $3 1 3
              IntCmp $4 ${DOT_MINOR} yesDotNetReg goNext yesDotNetReg
        
            goNext:
              ;Go to the next RegKey.
              IntOp $2 $2 + 1
              goto StartEnum
        
          yesDotNetReg:
            ;Now that we've found a good RegKey, let's make sure it's actually
            ;installed by getting the install path and checking to see if the 
            ;mscorlib.dll exists.
            EnumRegValue $2 HKLM "$1\policy\$3" 0
            ;$2 should equal whatever comes after the major and minor versions 
            ;(ie, v1.1.4322)
            StrCmp $2 "" noDotNet
            ReadRegStr $4 HKLM $1 "InstallRoot"
            ;Hopefully the install root isn't empty.
            StrCmp $4 "" noDotNet
            ;build the actuall directory path to mscorlib.dll.
            StrCpy $4 "$4$3.$2\mscorlib.dll"
            IfFileExists $4 yesDotNet noDotNet
        
          noDotNet:
            ;Nope, something went wrong along the way.  Looks like the proper .NETFramework isn't installed.  
            Push "NOK"
            Return
        
          yesDotNet:
            ;Everything checks out.  Go on with the rest of the installation.
            Push "OK"
            Return
        
        FunctionEnd
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多