Skip to content
17 changes: 13 additions & 4 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,19 @@ function Invoke-ExternalCommand {
return $true
}

function env($name,$global,$val='__get') {
$target = 'User'; if($global) {$target = 'Machine'}
if($val -eq '__get') { [environment]::getEnvironmentVariable($name,$target) }
else { [environment]::setEnvironmentVariable($name,$val,$target) }
function env($name, $global, $val='__get') {
$target = 'User'
$EnvironmentRegisterKey = 'HKCU:\Environment'
if ($global) {
$target = 'Machine'
Comment thread
r15ch13 marked this conversation as resolved.
Outdated
$EnvironmentRegisterKey = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
}
if ($val -eq '__get') {
(Get-Item -Path $EnvironmentRegisterKey).
GetValue($name, '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
} else {
Set-ItemProperty -Path $EnvironmentRegisterKey -Name $name -Value $val -Type 'ExpandString'
}
}

function isFileLocked([string]$path) {
Expand Down