I want to create an NSIS installer that checks for the .NET Framework and installs it if it's not there. Can you point me to a script for this? I'm very new to NSIS.
The version of .NET Framework (4.5 and later) installed on a machine is listed in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full. If the Full subkey is missing, then .NET Framework 4.5 or above isn't installed.
Reboot your computer and try installing the NET Framework. If still getting the same error message then try following the below-given steps. Open CMD (Command Prompt) in administrator mode. In the command prompt window, type the following command “net stop wuauserv” and press the enter button to stop the service.
Select Start > Control Panel > Programs > Programs and Features. Select Turn Windows features on or off. If not already installed, select Microsoft . NET Framework and click OK.
Try the DotNetVer script. It uses LogicLib and is quite easy to use.
Sample:
${If} ${HasDotNet4.0} DetailPrint "Microsoft .NET Framework 4.0 installed." ${If} ${DOTNETVER_4_0} AtLeastDotNetServicePack 1 DetailPrint "Microsoft .NET Framework 4.0 is at least SP1." ${Else} DetailPrint "Microsoft .NET Framework 4.0 SP1 not installed." ${EndIf} ${If} ${DOTNETVER_4_0} HasDotNetClientProfile 1 DetailPrint "Microsoft .NET Framework 4.0 (Client Profile) available." ${EndIf} ${If} ${DOTNETVER_4_0} HasDotNetFullProfile 1 DetailPrint "Microsoft .NET Framework 4.0 (Full Profile) available." ${EndIf} ${If} ${DOTNETVER_4_0} HasDotNetFullProfile 0 DetailPrint "Microsoft .NET Framework 4.0 (Full Profile) not available." ${EndIf} ${EndIf}
I had an issue with the "DotNET.nsh" pluging, which you can find somwhere, and simply used this solution (for .net 4.0, full install - which I needed, you can as well limit it to the client package):
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:
The banner stuff is optional, you could just use DetailPrint
or the like.
This way, you pull along the Web installer for .NET 4.0, but it's pretty small
(as opposed to .NET versions which didn't have one). The installer does the downloading
if it's needed, and you don't need kilometers of NSIS code.
!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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With