I do not know there is any other way of environment variables in a more practical way, I made a script in powershell to automate this process.
Limitations:
clear
write-host "Aguarde..."
[object[]]$r = (Get-WmiObject win32_product -Filter " name like 'JAVA %'")
$javaHome = "JAVA_HOME"
Write-Host "Valor atual do JAVA_HOME: $env:JAVA_HOME 'n"
$opcao = 0
$itensValidos = @()
foreach($item in $r){
if($item.InstallLocation -ne $null){
Write-Host $opcao - $item.Name - $item.InstallLocation
$itensValidos += $item
$opcao++
}
}
$selecionado = Read-Host "'nInforme qual instalação do java será definida em JAVA_HOME"
if($selecionado -lt 0 -or $selecionado -gt $itensValidos.Count -1){
Write-Host "Opção invalida"
}
[Environment]::SetEnvironmentVariable($javaHome, $itensValidos[$selecionado].InstallLocation +"lib" , 'Machine')
Running
AlltheinstalledsoftwaresthathaveJAVA_HOME
namearesearched,thefollowinglinesdisplaythemenuwiththevalidinstallationsofthejava(thosethathavethepathoftheinstallation),aftertherequestismadethepathnameofJAVA_HOME
andfinallythechangeismadewiththeJAVA
method.
Sources:
Windows PowerShell Tip of the Week
Environment class .net
Get-WmiObject