Search code examples
frameworksnsissilent-installer

Enable .Net Framework 3.5 SP1 from 'Programs and Features' and install it using NSIS


I am creating installer using nsis for my windows form application. I need .Net Framework 3.5 SP1 as pre-requisites for my application. So using NSIS i check if it is available in client machine or not. If not then it will install it silently. But it gives me an error. I know .Net Framework 3.5 SP1 is required to enable from 'Program and Features' in control panel.

So how can i enable feature '.NET FRAMEWORK 3.5' from control panel using NSIS script.

My nsis section to check and install .Net Framework 3.5 SP1 is :

 section
    SetOutPath "$temp\Pre_requisites"
    ; check and install .Net Framework 3.5SP1
    ReadRegStr $R1 HKLM "Software\Microsoft\NET Framework Setup\NDP\v3.5" "SP"
    ${If} $R1 != "1"
                   DetailPrint "Microsoft .NET Framework 3.5 SP1 needed. Installing..."              
                   File "$temp\Pre_requisites\dotnetfx35.exe"      
                   ExecWait '"$temp\Pre_requisites\dotnetfx35.exe" /q /norestart'
    ${Else}
    DetailPrint "Microsoft .NET Framework 3.5 SP1 Found."
    ${EndIf}
 sectionend

Error message is(I have tried this in windows 7 SP1 64bit):

enter image description here

Thanks..!


Solution

  • Execute below code. It execute dism.exe with enable feature parameter by command prompt for .Net Framework 3.5 online installation.

         section
            ; check and install .Net Framework 3.5SP1
            ReadRegStr $R1 HKLM "Software\Microsoft\NET Framework Setup\NDP\v3.5" "SP"
            ${If} $R1 != "1"
                           DetailPrint "Microsoft .NET Framework 3.5 SP1 needed. Installing..."              
                           nsExec::Exec 'cmd /c %windir%\system32\dism.exe /Online /Enable-Feature /FeatureName:NetFx3 /All'   
            ${Else}
            DetailPrint "Microsoft .NET Framework 3.5 SP1 Found."
            ${EndIf}
         sectionend