mirror of
https://github.com/actions/runner-images.git
synced 2025-12-14 05:07:02 +00:00
[Windows] Refactor PATH helpers (#8885)
This commit is contained in:
committed by
GitHub
parent
c73276d3f6
commit
bfe32a2b12
@@ -869,3 +869,39 @@ function Test-FileSignature {
|
||||
throw "Signature thumbprint do not match expected."
|
||||
}
|
||||
}
|
||||
|
||||
function Update-Environment {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Updates the environment variables by reading values from the registry.
|
||||
|
||||
.DESCRIPTION
|
||||
This function updates current environment by reading values from the registry.
|
||||
It is useful when you need to update the environment variables without restarting the current session.
|
||||
|
||||
.NOTES
|
||||
The function requires administrative privileges to modify the system registry.
|
||||
#>
|
||||
|
||||
$locations = @(
|
||||
'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
|
||||
'HKCU:\Environment'
|
||||
)
|
||||
|
||||
# Update PATH variable
|
||||
$pathItems = $locations | ForEach-Object {
|
||||
(Get-Item $_).GetValue('PATH').Split(';')
|
||||
} | Select-Object -Unique
|
||||
$Env:PATH = $pathItems -join ';'
|
||||
|
||||
# Update other variables
|
||||
$locations | ForEach-Object {
|
||||
$key = Get-Item $_
|
||||
foreach ($name in $key.GetValueNames()) {
|
||||
$value = $key.GetValue($name)
|
||||
if (-not ($name -ieq 'PATH')) {
|
||||
Set-Item -Path Env:$name -Value $value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user