powershell - 安装 .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{
}
}
解决方案
我发现我自己的问题的解决方案是
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 框架版本。
推荐阅读
- python-3.x - Python:关闭多处理线程会停止整个程序
- node.js - 如何将此 cURL 命令重写为 axios 代码
- c - if 语句后的 Printf 命令不起作用
- javascript - 如何将 decorator() 的语法更改为 @decorator
- python - 在 init 方法中将变量分配为 None 时抑制 PyCharm 警告
- python - 无法使用scrapy抓取多个页面
- c# - 如何在 ASP.NET MVC 中集成 Authorize.Net 支付并接收支付状态?
- react-native - 你现在推荐哪个 React Native 的 Js 后端框架?
- r - 在R中的分组条形图中组合堆叠条形图
- css - Bootstrap 4.3 中背景的 img-retina 替代品