Skip to content

Commit

Permalink
(chocolateyGH-7) warn when install is not done in admin mode
Browse files Browse the repository at this point in the history
If the environment variables are being created as USER instead of
SYSTEM, warn the user about this so they can take manual actions if
this is not what they wanted.
  • Loading branch information
ferventcoder committed Feb 11, 2015
1 parent 38c5991 commit 22a778e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nuget/chocolatey/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,15 @@ param(
[string]$folder
)
$environmentTarget = [System.EnvironmentVariableTarget]::User
# removing old variable
Install-ChocolateyEnvironmentVariable -variableName "$chocInstallVariableName" -variableValue $null -variableType $environmentTarget
if (Test-ProcessAdminRights) {
Write-Debug "Administrator installing so using Machine environment variable target instead of User."
$environmentTarget = [System.EnvironmentVariableTarget]::Machine
# removing old variable
Install-ChocolateyEnvironmentVariable -variableName "$chocInstallVariableName" -variableValue $null -variableType $environmentTarget
} else {
Write-Warning "Setting ChocolateyInstall Environment Variable on USER and not SYSTEM variables.`n This is due to either non-administrator install OR the process you are running is not being run as an Administrator."
}

Write-Output "Creating $chocInstallVariableName as an environment variable (targeting `'$environmentTarget`') `n Setting $chocInstallVariableName to `'$folder`'"
Expand Down Expand Up @@ -297,6 +301,8 @@ param(
if (Test-ProcessAdminRights) {
Write-Debug "Administrator installing so using Machine environment variable target instead of User."
$environmentTarget = [System.EnvironmentVariableTarget]::Machine
} else {
Write-Warning "Setting ChocolateyInstall Path on USER PATH and not SYSTEM Path.`n This is due to either non-administrator install OR the process you are running is not being run as an Administrator."
}

Install-ChocolateyPath -pathToInstall "$chocolateyExePath" -pathType $environmentTarget
Expand Down

0 comments on commit 22a778e

Please sign in to comment.