nsis DotNET Sample Example


Example

Here's an example on how to use the values in the registry to check for dotNET 4.5 or higher. I'd recommend putting this snippet of code somewhere like .OnInit as this will execute before anything else happens; this way it checks for .NET before any files get copied or registry changes take place.

;=#
;= Define the registry key we're looking for.
!define DOTNET  `SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full`

Section "Main"
    ClearErrors ;= Clear any errors we may have encountered before hand.
    ReadRegDWORD $0 HKLM `${DOTNET}` `Release` ;= Read the value of Release.
    IfErrors +3 ;= If there is an error than there is no .NET installed so we jump 3 lines down which lands on MessageBox.
    IntCmp $0 394806 +5 0 +5    ;= Compares the value for v4.6.2 if it matches then we jump 5 lines and avoids the MessageBox
    IntCmp $0 394802 +4 0 +4    ;= Remember to check for Windows 10's value aswell as the above line won't.
    MessageBox MB_ICONSTOP|MB_TOPMOST `You must have v4.6.2 or greater of the .NET Framework installed. Launcher aborting!` ;= If the check failed then we alert the user the required version wasn't found.
    Call Unload ;= We call the Unload function here because we failed the .NET check.
    Quit ;= Closes the Launcher
SectionEnd