我尝试通过下面的 PowerShell 脚本安装 MSU,但它没有安装。我不知道 PowerShell 脚本。请有人给我修改这个脚本的最佳方法。我很期待听到。
Start-Process "C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu" -ArgumentList "/quiet /norestart"
最佳答案
为了能够将参数传递给通过 Start-Process
启动的进程,(可能是位置隐含的)-FilePath
参数必须是真正的可执行文件,而不仅仅是一个文档,这就是 . msu
文件是。
因此,您必须将.msu
文件注册为显式处理的可执行文件传递给-FilePath
,即wusa.exe
(请注意 -ArgumentList
参数末尾的 /quiet/norestart
):
Start-Process `
-FilePath "$env:SystemRoot\System32\wusa.exe" `
-ArgumentList 'C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu /quiet /norestart'
注意:
为了等待安装完成,请添加
-Wait
开关。要另外检查进程的退出代码以确定安装是否成功,请添加
-PassThru
开关,在变量中捕获生成的进程信息对象,然后检查它的.ExitCode
属性。
但是,有一个技巧可以简化上述过程:将 wusa.exe
调用通过管道传输到 Write-Output
,这会强制它同步执行(作为 GUI-子系统应用程序,wusa.exe
否则会异步运行),并将其退出代码记录在自动 $LASTEXITCODE
变量中:
# Note the "| Write-Output" at the end of the line,
# which makes wusa.exe run synchronously and records its process
# exit code in $LASTEXITCODE.
& "$env:SystemRoot\System32\wusa.exe" C:\Installer\windows10.0-kb4520062-x64_9f2a827f11f945d19bd26de6f113f611a38bb8a1.msu /quiet /norestart | Write-Output
if ($LASTEXITCODE -ne 0)
throw "wusa.exe indicates failure; exit code was: $LASTEXITCODE"
}
'Installation succeeded.'
关于windows - 无法通过 PowerShell 脚本安装 Microsoft 更新(修补程序)-msu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72482039/