加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 10:49:20 所属栏目:百科 来源:网络整理
导读:执行环境:Windows Server 2012 R2 VC++下载链接 ? 这里有个问题,虽说可以静默安装,但是未对当前系统检测是否已安装vc++补丁,望大佬指点 ? # 自动安装Set -ExecutionPolicy - Force remotesigned# 获取当前脚本绝对路径$path = Split-Path - Parent $MyIn

执行环境:Windows Server 2012 R2

VC++下载链接

?

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

?

# 自动安装
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读