Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set-EnvironmentVariable writes an error when installing Chocolatey as SYSTEM #1043

Closed
splatteredbits opened this issue Nov 8, 2016 · 3 comments

Comments

@splatteredbits
Copy link
Contributor

What You Are Seeing?

After installing Chocolatey as SYSTEM, the following handled error is left in $Global:Error:

At C:\Windows\TEMP\chocolatey\chocInstall\tools\chocolateyInstall\helpers\functions\Set-EnvironmentVariable.ps1:81 char:5
+     $registryType = $win32RegistryKey.GetValueKind($Name)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at Set-EnvironmentVariable, C:\Windows\TEMP\chocolatey\chocInstall\tools\chocolateyInstall\helpers\functions\Set-EnvironmentVariable.ps1: line 81
at Install-ChocolateyEnvironmentVariable, C:\Windows\TEMP\chocolatey\chocInstall\tools\chocolateyInstall\helpers\functions\Install-ChocolateyEnvironmentVariable.ps1: line 100
at Set-ChocolateyInstallFolder, C:\Windows\TEMP\chocolatey\chocInstall\tools\chocolateysetup.psm1: line 166
at Initialize-Chocolatey, C:\Windows\TEMP\chocolatey\chocInstall\tools\chocolateysetup.psm1: line 78
at <ScriptBlock>, C:\Windows\TEMP\chocolatey\chocInstall\tools\chocolateyInstall.ps1: line 16
at <ScriptBlock>, <No file>: line 194
at <ScriptBlock>, E:\Build\WhsInit\Initialize-Computer.ps1: line 183
at <ScriptBlock>, <No file>: line 1
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : IOException

What is Expected?

The code "handles" this exception with a try/catch block with an empty catch block. Unfortunately, PowerShell still puts handled excetpions in $Global:Error. I expect that handled errors should leave no errors in the $Global:Error array. (Our nightly process sends transcripts of its works and we get a report everyday of errors. These errors give use false negatives which lowers the likelihood we'll see real errors.)

How Did You Get This To Happen? (Steps to Reproduce)

  • Open a PowerShell prompt as SYSTEM: psexec -d -i -s powershell.exe.
  • Delete the ChocolateyInstall environment variable.
  • Install chocolatey.
  • After the install $Global:Error has the above error in it.
@splatteredbits splatteredbits changed the title Set-EnvironmentVariable writes an error when run as SYSTEM Set-EnvironmentVariable writes an error when installing Chocolatey as SYSTEM Nov 8, 2016
@ferventcoder
Copy link
Member

@splatteredbits what are you hoping that is done here (as far as code changes)?

@ferventcoder ferventcoder added this to the 0.10.4 milestone Nov 8, 2016
@ferventcoder
Copy link
Member

Simple fix or something more involved?

@splatteredbits
Copy link
Contributor Author

A test for the existence of the key and/or value rather than a try/catch. I'll get a pull request put together.

@ferventcoder ferventcoder self-assigned this Nov 13, 2016
ferventcoder pushed a commit that referenced this issue Mar 18, 2017
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.
ferventcoder added a commit that referenced this issue Mar 18, 2017
* pr1044:
  (GH-1043) Fix: Set-EnvironmentVariable writes error when SYSTEM
ferventcoder added a commit that referenced this issue Mar 18, 2017
* stable:
  (GH-1043) Fix: Set-EnvironmentVariable writes error when SYSTEM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants