NSIS Script - Check existence of .Net Framework 4.8 and install it

35 views Asked by At

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 .NET Framework 4.8 or later is available on the machine then it should proceed with the Main application installation process.

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

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", script has compiled successfully and the Windows installer has been created. During the execution of the windows installer, i found that downloading of .NET framework is happening simultaneously along with the installation of the application. The wizard is getting closed automatically once the application is installed and not checking whether the .NET framework is installed or not.

Can you please suggest if the script is correct for checking the existence of .NET framework 4.8 and installing it? Also, provide me a suggestion on executing the steps one after the other as follows

  1. Check existence of .NET framework 4.8 or later
  2. If the framework exists, simply proceed with the installation of the application.
  3. If the framework does not exist, download the .NET framework installer file, install it , wait for the installation to complete and proceed with the application installation
0

There are 0 answers