使用PowerShell 自动安装VC++补丁

执行环境:Windows Server 2012 R2

VC++下载链接

这里有个问题,虽说可以静默安装,但是未对当前系统检测是否已安装vc++补丁,望大佬指点

# author:lttr <www.cnblogs.com/GoCircle> 
# date:2019-08-09
# 自动安装 Set
-ExecutionPolicy -Force remotesigned # 获取当前脚本绝对路径 $path = Split-Path -Parent $MyInvocation.MyCommand.Definition; $Net = "vcredist_x64.exe"; Set-Location $path; function Show-Progress ($file, $arguments){ $process = Start-Process $file $arguments -Verb RunAs -PassThru for($i = 0; $i -le 100; $i = ($i + 1) % 100) { Write-Progress -Activity "正在安装 C++补丁" -PercentComplete $i Start-Sleep -Milliseconds 100 if ($process.HasExited) { Write-Progress -Activity "Installer" -Completed if ($process.HasExited) { # 提示安装状态 if ($process.ExitCode -ne 0) { Write-Warning "安装过程返回错误代码: $($process.ExitCode)"; }else { Write-Host "成功安装C++补丁。" } break } } } } function InstallNet ($filepath,$filename){ $NetFxPath = $filepath + $filename; #验证安装文件是否存在 If(Test-Path -Path $NetFxPath) { Write-Host "正在安装 C++补丁 ..." Show-Progress $NetFxPath "/q /norestart" } Else { Write-Warning "找不到C++补丁安装包。" } } InstallNet $path $Net

原文地址:https://www.cnblogs.com/GoCircle/p/11226584.html