From d24dbcbca6a3720ee4bf9552335453427e5a7f5b Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 8 Nov 2016 16:20:34 -0800 Subject: [PATCH] (GH-1043) Fix: Set-EnvironmentVariable writes error when SYSTEM Set-EnvironmentVariable uses try/catch to handle when a registry key doesn't exist. When running as SYSTEM, a local key may not exist, so an error is logged as a warning. Add explicit check to see if the environment variable registry key exists before tring to get its type to avoid logging an error/warning. --- .../helpers/functions/Set-EnvironmentVariable.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/chocolatey.resources/helpers/functions/Set-EnvironmentVariable.ps1 b/src/chocolatey.resources/helpers/functions/Set-EnvironmentVariable.ps1 index 9c75127756..cbd052e76e 100644 --- a/src/chocolatey.resources/helpers/functions/Set-EnvironmentVariable.ps1 +++ b/src/chocolatey.resources/helpers/functions/Set-EnvironmentVariable.ps1 @@ -78,7 +78,10 @@ param ( [Microsoft.Win32.RegistryValueKind]$registryType = [Microsoft.Win32.RegistryValueKind]::String try { - $registryType = $win32RegistryKey.GetValueKind($Name) + if ($win32RegistryKey.GetValueNames() -contains $Name) + { + $registryType = $win32RegistryKey.GetValueKind($Name) + } } catch { # the value doesn't yet exist # move along, nothing to see here