Skip to content

Conversation

@revoconner
Copy link

Description Of Changes

Added preservation of additional volatile environment variables (APPDATA, LOCALAPPDATA, USERPROFILE, HOMEDRIVE, HOMEPATH) that should not be overwritten when refreshing from registry. These are captured before calling the generated _env.cmd and restored afterward, matching the existing pattern for USERNAME and PROCESSOR_ARCHITECTURE.

Motivation and Context

This is the same class of bug as #3681 (fixed for TEMP/TMP in v2.6.0). When HKCU\Environment contains incorrect entries for volatile variables, refreshenv overwrites the session's correct values. In my case, an incorrect APPDATA entry caused VS Code to create its data directory in the wrong location (AppData\Code instead of AppData\Roaming\Code).

Windows generates these volatile variables at login and they should not be overwritten from potentially stale or incorrect registry entries.

Testing

  1. Added incorrect APPDATA entry to HKCU\Environment
  2. Ran refreshenv
  3. Verified APPDATA retained correct session value instead of incorrect registry value

Operating Systems Testing

  • Windows 11 24H2 LTSC (10.0.26100.6899)

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

Fixes #3829

Add handling for additional volatile environment variables (APPDATA,
LOCALAPPDATA, USERPROFILE, HOMEDRIVE, HOMEPATH) that should not be
overwritten when refreshing from registry.

Without this change, these user-specific paths get incorrectly reset
to system defaults when running RefreshEnv.cmd.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refreshenv overwrites volatile environment variables (APPDATA, LOCALAPPDATA, USERPROFILE, etc.)

1 participant