从 'Programs and Features' 启用 .Net Framework 3.5 SP1 并使用 NSIS 安装它

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

我正在使用 nsis 为我的 windows 表单应用程序创建安装程序。我需要 .Net Framework 3.5 SP1 作为我的应用程序的先决条件。所以使用 NSIS 我检查它是否在客户端机器上可用。如果没有,它将以静默方式安装。但它给了我一个错误。我知道需要 .Net Framework 3.5 SP1 才能从控制面板中的 'Program and Features' 启用。

那么我如何使用 NSIS 脚本从控制面板启用功能“.NET FRAMEWORK 3.5”。

我检查和安装 .Net Framework 3.5 SP1 的 nsis 部分是:

 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

错误消息是(我在 windows 7 SP1 64 位中试过):

谢谢..!

近99,9%的Windows7个安装默认安装了.Net 3.5。因为它是源代码中内置的功能。 请检查注册表以找出安装了 .net 的确切版本。如果您确实需要在 Windows 7 下安装 .net 3.5,请查看 https://technet.microsoft.com/de-de/library/dn482069.aspx。因为在 Windows 下需要使用 DSIM 安装 .net 3.5 7. Installer 仅适用于 Windows XP 及更低版本。

执行下面的代码。它通过 .Net Framework 3.5 在线安装的命令提示符执行 dism.exe 和 enable feature 参数。

     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