The environment gets populated on process start-up which is why you'll need to restart the process.
You can update the environment by reading it from the registry. Maybe with a script like the following:
function Update-Environment {
$locations = 'HKLM:SYSTEMCurrentControlSetControlSession ManagerEnvironment',
'HKCU:Environment'
$locations | ForEach-Object {
$k = Get-Item $_
$k.GetValueNames() | ForEach-Object {
$name = $_
$value = $k.GetValue($_)
if ($userLocation -and $name -ieq 'PATH') {
Env:Path += ";$value"
} else {
Set-Item -Path Env:$name -Value $value
}
}
$userLocation = $true
}
}
(untested)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…