Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-699) Fix: PATH may break on Install-ChocolateyPath
The fixes for GH-303 (e050c22) had an interesting and terrible side effect. When you don't expand the value and then you update using `[Environment]::SetEnvironmentVariable($Name, $Value, $Scope)`, it has the side effect of overwriting the original registry value type and saves the values as `REG_SZ` instead of keeping it as `REG_EXPAND_SZ`. Then all of the tools in WinDir no longer work all of a sudden and it's somewhat perplexing what happened as everything looks appropriate when you inspect the values. You can verify if you are affected by opening a new command line and typing `where.exe choco` and the system cannot find where.exe, which is at `C:\Windows\System32\where.exe`. You are only affected if you installed (explicitly installed, not upgraded) one of the following beta releases directly: * https://chocolatey.org/packages/chocolatey/0.9.10-beta-20160411 * https://chocolatey.org/packages/chocolatey/0.9.10-beta-20160422 * https://chocolatey.org/packages/chocolatey/0.9.10-beta-20160503 This is fixed by attempting to ask the registry what the value type is for the particular key and falling back to `REG_SZ` when it is not found. Environment variables are always either String or ExpandString. As a further step, if it is the `PATH` variable, it will always be saved as ExpandString (`REG_EXPAND_SZ`). Then set the value using `[Microsoft.Win32.Registry]::SetValue` instead because it allows setting the value type.
- Loading branch information