$baseURL = "https://api.adoptium.net/v3/assets/feat ... ases/11/ga" # Adoptium binaries and links
# Get versions and then [0] of the array that is returned to get the latest version
$response = Invoke-RestMethod -Uri $baseURL
$latestVersion = ($response.version_data.openjdk_version)[0]
# Locate the Windows MSI Installer
$downloadURL = ""
foreach ($asset in $response.binaries) {
if ($asset.architecture -eq "x64" -and $asset.image_type -eq "jre" -and $asset.os -eq "windows") {
$downloadURL = $asset.installer.link
$downloadPath = "$env:TEMP\$($asset.installer.name)" # Contains just the msi file name
break
}
}
# Download and run the installer
$global:progressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $downloadURL -OutFile $downloadPath
& $downloadPath
После этого я хочу автоматизировать установку, но не смог заставить это работать. Я до сих пор дошел до этого, но это не работает. Моя цель — автоматически выбрать четыре доступных параметра в установщике JRE:
- Добавить в PATH (выбрано по умолчанию)
- Связать .jar (выбрано по умолчанию)
- Установить переменную JAVA_HOME (не выбрано по умолчанию)
- Разделы реестра JavaSoft (Oracle) (не выбрано по умолчанию)
# Define the path to the MSI installer
$installerPath = "$env:TEMP\OpenJDK11U-jre_x64_windows_hotspot_11.0.23_9.msi"
# Define the arguments for msiexec
$msiArgs = @(
"/i", "$installerPath", # Specify the path to the MSI installer
"/qn", # Quiet mode (no UI)
"/norestart", # Do not restart after installation
"INSTALLDIR=`"C:\Program Files\Java\jdk-11`"", # Specify the installation directory (change as needed)
"ADDLOCAL=FeatureMain,FeatureEnvironment,FeatureJarFileRunWith,FeatureJNLPFileRunWith,FeatureJavaHome", # Specify features to install
"SETUP_AUTO_UPDATE=0", # Disable automatic updates
"INSTALL_SILENT=Enable", # Enable silent installation
"ASSOCIATE_JNLP=Enable", # Associate .jnlp files
"ASSOCIATE_JAR=Enable", # Associate .jar files
"ASSOCIATE_JAD=Enable", # Associate .jad files
"INSTALLDIR_CONFESS=Enable" # Set installation directory
)
# Run msiexec with the defined arguments
Start-Process "msiexec.exe" -ArgumentList $msiArgs -Wait
Подробнее здесь: https://stackoverflow.com/questions/784 ... ion-and-co