Skip to content
⌘ NSIS Forum Archive

NSIS Script - Check existence of .Net Framework 4.8 and install it (If not available)

1 posts

Kamal14042015#

NSIS Script - Check existence of .Net Framework 4.8 and install it (If not available)

Hello,

I am new to NSIS and learning to write a script that creates a windows installer using NSIS software utility tool.

I have a requirement where i need to check the existence of .NET Framework 4.8, download from Microsoft official website and install it only if it is not available on a machine. If the required version or later is available on the machine then it should proceed with the Main installation process.

I have written the following script but the .NET framework installation is not happening during the installation of the application.

Section "CheckAndInstallDotNet"
; Define the registry key path for .NET Framework 4.8
Var /GLOBAL NETFRAMEWORK48_REGKEY
StrCpy $NETFRAMEWORK48_REGKEY "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"

; Check if .NET Framework 4.8 is installed by querying the Release key in the registry
ClearErrors
ReadRegDWORD $0 HKLM $NETFRAMEWORK48_REGKEY "Release"
IfErrors not_installed
IntCmp $0 528040 installed not_installed

; If .NET Framework 4.8 is already installed
Goto done

installed:
MessageBox MB_ICONINFORMATION ".NET Framework 4.8 is already installed on your system."
Goto done

; Label for not installed
not_installed:
MessageBox MB_ICONEXCLAMATION|MB_OK ".NET Framework 4.8 is not installed. The installer will now proceed to download and install it."
NSISdl::download /TIMEOUT=30000 "https://dotnet.microsoft.com/en-us/download/dotnet-framework/thank-you/net48-web-installer" "$TEMP\dotNetFramework48Installer.exe"
ExecWait '"$TEMP\dotNetFramework48Installer.exe" /q /norestart'
done:
SectionEnd


I have compiled the script using the "HM NIS Edit", the script has compiled successfully and the Windows installer has been created. During the execution of the installation i found that downloading of .NET framework is happening along with the installation of the application.

Can you please suggest if the script is correct for checking the existence of .NET framework 4.8 ? Also, provide me a script on executing the steps one after the other as follows
  • Check existence of .NET framework 4.8 or later
  • If the framework exists then simply move to the installation of the application.
  • If the framework does not exist then download the .NET framework installer file, install it , wait for the installation to complete and proceed with the application installation.

Thanks and Regards,
Kamal