首页 > 解决方案 > 安装 .Net Framework 4.7.1 后是否需要重新启动 windows 服务器

问题描述

我从 Windows 7 机器上了解到,当我安装 .Net Framework 4.7.1 时,它需要重新启动才能生效,否则使用此 .Net fx 版本设计的应用程序无法启动。

那么,如果我在 Windows 服务器版(2008r2 以后)上安装 .Net fx 4.7.1,是否还需要重新启动?

我想通过一个脚本自动安装 .Net fx 和应用程序,所以我已经实现了脚本,但不确定重启 windows 服务器

如果我确实想重新启动 windows 服务器,那么可以将其添加为基于 power shell 的脚本的一部分吗?

编辑我的示例脚本如下

if(Test-Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'){
$NetRegKey = Get-Childitem %%'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'
if($NetRegKey){
    $Release = $NetRegKey.GetValue("Release")
    if($Release){
        if($Release -lt 461308){
            try{
                $prc = Start-Process C:\NDP471-KB4033342-x86-x64-AllOS-ENU.exe -Wait
            }
            catch{

            }
        }
    }       
    }
}
else{
try{
    $prc = Start-Process C:\NDP471-KB4033342-x86-x64-AllOS-ENU.exe -Wait
}
catch{

}
}

标签: powershellwindows-server-2012.net-framework-version

解决方案


我发现我自己的问题的解决方案是

if( -NOT ((Test-Path 'HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.7.1') -or (Test-Path 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe') -or (Test-Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'))) {

Start-Process .\DotNetFX471\NDP471-KB4033342-x86-x64-AllOS-ENU.exe -RedirectStandardError "DotNetInstallationStatus.txt" -Wait
if ($LastExitCode -ne 0){
    Write-Host "ERROR: "
    Get-Content -Path .\appInstallStatus.txt
    return
}
Write-Host ".Net Framework installation is completed successfully"
}

Write-Host "Running CIE installer, please wait..."

$installerParam = "--p 'C:\Program Files\APP'"
Start-Process .\install.exe $installerParam -RedirectStandardError "appInstallStatus.txt" -Wait

if ($LastExitCode -ne 0){
    Write-Host "ERROR: "
    Get-Content -Path .\appInstallStatus.txt
    return
}

一旦我们在任何 Windows 服务器上安装了 .Net 框架,我们应该会看到在“C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe”创建的文件夹,运行这个 MSBuild.exe 来获取版本。通常,如果我们没有 .Net 框架,则此文件夹将不可用,但如果此文件夹可用,则您将通过运行此 MSBuild.exe 文件获得正确的 .Net 框架版本。


推荐阅读