mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-22 10:07:37 +00:00
## Summary of the Pull Request Accumulated information from internal transition about the modules development, and reworked it to be added in dev docs. Also the dev docs intself was restructured to be more organized. New pages was verified by transition team. ## PR Checklist - [x] **Dev docs:** Added/updated --------- Co-authored-by: Zhaopeng Wang (from Dev Box) <zhaopengwang@microsoft.com> Co-authored-by: Hao Liu <liuhao3418@gmail.com> Co-authored-by: Peiyao Zhao <105847726+zhaopy536@users.noreply.github.com> Co-authored-by: Mengyuan <162882040+chenmy77@users.noreply.github.com> Co-authored-by: zhaopeng wang <33367956+wang563681252@users.noreply.github.com> Co-authored-by: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com>
3.3 KiB
3.3 KiB
Environment Variables
Public overview - Microsoft Learn
Quick Links
All Issues
Bugs
Pull Requests
Checklist
Overview
Environment Variables is a PowerToys module that provides an easy and convenient way to manage Windows environment variables. It offers a modern user interface for viewing, editing, and managing both user and system environment variables.
Features
- View and edit user and system environment variables in a unified interface
- Create profiles to group and manage sets of variables together
- Profile-based variable management with on/off toggles
- Automatic backup of existing variables when overridden by a profile
- Restoration of original values when profiles are disabled
How It Works
Profiles
Profiles are collections of environment variables that can be enabled or disabled together. When a profile is enabled:
- Variables in the profile override existing User variables with the same name
- Original values are automatically backed up for restoration when the profile is disabled
- Only one profile can be active at a time
Variable Precedence
The module follows this precedence order for environment variables:
- Active profile variables (highest precedence)
- User variables
- System variables (lowest precedence)
Architecture
The Environment Variables module is structured into three main components:
Project Structure
EnvironmentVariables/ # Contains assets, main windows, and telemetry
EnvironmentVariablesModuleInterface # Interface definitions and package configurations
EnvironmentVariableUILib # Abstracted UI methods and implementations
Key Components
- Main Window Framework: Builds the modern Windows desktop UI, handles Windows messages, resource loading, and window closing operations
- Project Configuration: Defines settings and configurations for the module
- UI Implementation: Contains the user interface components and the backend logic
Implementation Details
Key Functions
- OpenEnvironmentKeyIfExists: Accesses environment information through registry keys
- SetEnvironmentVariableFromRegistryWithoutNotify: Sets variables directly to registry instead of using Environment API, avoiding the 1-second timeout for settings change notifications
- GetVariables: Reads variables directly from registry instead of using Environment API to prevent automatic variable expansion
Technical Notes
- The module reads and writes variables directly to the registry instead of using the Environment API
- This direct registry access approach is used because the Environment API automatically expands variables and has a timeout for notifications
- When a profile variable has the same name as an existing User variable, a backup is created with a naming pattern:
VARIABLE_NAME_powertoys_PROFILE_NAME