Skip to content

Commit

Permalink
(GH-902) Fix: User changed to SYSTEM during env update
Browse files Browse the repository at this point in the history
Previously, running RefreshEnv / Update-SessionEnvironment would change
current user to SYSTEM. This is due to Machine environment variables
noting user as SYSTEM. To stop this, set the original username as a
variable and reset the Username environment variable after the refresh.

Do the same for Processor_Architecture.
  • Loading branch information
ferventcoder committed Mar 19, 2017
1 parent e7ce79f commit cb6b92c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ None
Write-Verbose "Refreshing environment variables from the registry."
}

$userName = $env:USERNAME
$architecture = $env:PROCESSOR_ARCHITECTURE
$psModulePath = $env:PSModulePath

#ordering is important here, $user comes after so we can override $machine
Expand All @@ -82,6 +84,10 @@ None
# PSModulePath is almost always updated by process, so we want to preserve it.
$env:PSModulePath = $psModulePath

# reset user and architecture
if ($userName) { $env:USERNAME = $userName; }
if ($architecture) { $env:PROCESSOR_ARCHITECTURE = $architecture; }

if ($refreshEnv) {
Write-Output "Finished"
}
Expand Down
8 changes: 8 additions & 0 deletions src/chocolatey.resources/redirects/RefreshEnv.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ goto main
del /f /q "%TEMP%\_envset.tmp" 2>nul
del /f /q "%TEMP%\_envget.tmp" 2>nul

:: capture user / architecture
SET "OriginalUserName=%USERNAME%"
SET "OriginalArchitecture=%PROCESSOR_ARCHITECTURE%"

:: Set these variables
call "%TEMP%\_env.cmd"

:: reset user / architecture
SET "USERNAME=%OriginalUserName%"
SET "PROCESSOR_ARCHITECTURE=%OriginalArchitecture%"

echo | set /p dummy="Finished."
echo .

0 comments on commit cb6b92c

Please sign in to comment.