NSIS: How to ensure .NET Framework 4.6 is installed
You want to create a Windows Installer with NSIS for a project using .NET version 4.6?
Actually NSIS provides a tutorial for detecting and installing .NET versions less than 4.6 [1]. For this reason, here you can find how to ensure that the version 4.6 is installed.
With following command you can identify if .NET 4.6 is installed:
!define ReleaseDotNet46 393297; This is the release number of the .NET-Version 4.6 in Windows 7
ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Release"
IntCmp "$0" "${ReleaseDotNet46}" Installed NotInstalled Installed
For more information about how to determine which .NET Framework Version is installed see https://msdn.microsoft.com/de-de/library/hh925568%28v=vs.110%29.aspx#net_d.
If .NET 4.6 is not installed, it can be downloaded and installed using following commands:
!define DOWNLOAD_URL https://download.microsoft.com/download/C/3/A/C3A5200B-D33C-47E9-9D70-2F7C65DAAD94/NDP46-KB3045557-x86-x64-AllOS-ENU.exe
!define NETInstaller "$TEMP\dotNet46Setup.exe"
NSISDL::download ${DOWNLOAD_URL} "${NETInstaller}"
Pop $0
${If} $0 == "cancel"
goto SetupGoOnWithoutDotNet
${ElseIf} $0 != "success"
goto SetupGoOnWithoutDotNet
${EndIf}
${StdUtils.ExecShellWaitEx} $0 $1 "${NETInstaller}" "open" ""
StrCmp $0 "error" ExecFailed
StrCmp $0 "no_wait" ExecFailed
StrCmp $0 "ok" WaitForProc
Abort
WaitForProc:
${StdUtils.WaitForProcEx} $2 $1
StrCmp "$2" "" EndInstallDotNet46
StrCmp "$2" "0" EndInstallDotNet46
StrCmp "$2" "3010" EndInstallDotNet46
StrCmp "$2" "8192" EndInstallDotNet46
If you have further questions, just create a comment.
[1] http://nsis.sourceforge.net/DotNetChecker_plug-in (27.10.2015)