Check for .NET4.5+ with NSIS

前端 未结 6 1869
暗喜
暗喜 2020-12-28 20:22

All, I am aware of the following methods to check the framework version in NSIS. For .NET4.0+ I currently use

Function IsDotNetInstalled

    StrCpy $0 \"0\         


        
6条回答
  •  被撕碎了的回忆
    2020-12-28 21:01

    In the end I went with the following function which utilises the answer above. This method first creates a directory "$INSTDIR\dotNETFramework" which contains the .NET web installer:

    Function CheckAndInstallDotNet
        ; Installer dotNetFx45_Full_setup.exe avalible from http://msdn.microsoft.com/en-us/library/5a4x27ek.aspx
        ; Magic numbers from http://msdn.microsoft.com/en-us/library/ee942965.aspx
        ClearErrors
        ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Release"
        IfErrors NotDetected
        ${If} $0 >= 378389
            DetailPrint "Microsoft .NET Framework 4.5 is installed ($0)"
        ${Else}
        NotDetected:
            MessageBox MB_YESNO|MB_ICONQUESTION ".NET Framework 4.5+ is required for ProgramX2013, \
                do you want to launch the web installer? This requires a valid internet connection." IDYES InstallDotNet IDNO Cancel 
            Cancel:
                MessageBox MB_ICONEXCLAMATION "To install ProgramX, Microsoft's .NET Framework v${DOT_MAJOR}.${DOT_MINOR} \
                    (or higher) must be installed. Cannot proceed with the installation!"
                ${OpenURL} "${WWW_MS_DOTNET4_5}"
                RMDir /r "$INSTDIR" 
                SetOutPath "$PROGRAMFILES"
                RMDir "$INSTDIR" 
                Abort
    
            ; Install .NET4.5.
            InstallDotNet:
                DetailPrint "Installing Microsoft .NET Framework 4.5"
                SetDetailsPrint listonly
                ExecWait '"$INSTDIR\dotNETFramework\dotNetFx45_Full_setup.exe" /passive /norestart' $0
                ${If} $0 == 3010 
                ${OrIf} $0 == 1641
                    DetailPrint "Microsoft .NET Framework 4.5 installer requested reboot."
                    SetRebootFlag true 
                ${EndIf}
                SetDetailsPrint lastused
                DetailPrint "Microsoft .NET Framework 4.5 installer returned $0"
        ${EndIf}
    
        ; Now remove the dotNETFramework directory and contents.
        RMDir /r "$INSTDIR\dotNETFramework" 
    FunctionEnd
    

    This method seemlessley launches the .NET4.5 installer if there is an internet connection and returns after the installation is complete.

    I hope this helps someone else.

提交回复
热议问题