https://www.java.com/releases/
基本上就是装 8u301,删所有旧版本,请小心使用
[PowerShell] 纯文本查看 复制代码 # PowerShell script to automatically download and install the latest Java SE (JDK) version 8u301
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Download and install Offline Java installer
$uri = "https://javadl.oracle.com/webapps/download/AutoDL?BundleId=245045_d3c52aa6bfa54d3ca74e617f18309292"
$path = "$PSScriptRoot\jdk8_x64.exe"
(New-Object System.Net.WebClient).DownloadFile($uri, $path)
Start-Process $PSScriptRoot\jdk8_x64.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait
echo $?
$RegUninstallPaths = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
)
# Stop running Java process
Get-CimInstance -ClassName 'Win32_Process' | Where-Object {$_.ExecutablePath -like '*Program Files\Java*'} | Select-Object @{n='Name';e={$_.Name.Split('.')[0]}} | Stop-Process -Force
$VersionsToKeep = '8 Update 301'
$UninstallSearchFilter = {($_.GetValue('DisplayName') -like 'Java*') -and ($_.GetValue('Publisher') -like 'Oracle*') -and ($_.GetValue('DisplayName') -notlike "*$VersionsToKeep*")}
# Uninstall all older Java versions (incl. Auto Updater)
foreach ($Path in $RegUninstallPaths) {
if (Test-Path $Path) {
Get-ChildItem $Path | Where-Object $UninstallSearchFilter | foreach {
Write-Host Uninstalling $_.GetValue('DisplayName') ...
Start-Process 'C:\Windows\System32\msiexec.exe' "/X$($_.PSChildName) /qn /norestart" -Wait
}
}
}
|