Windows Environment Variables Reference
Understanding Windows Environment Variables
Environment variables are dynamic named values that can affect the way running processes will behave on a computer. In Windows, they are crucial for system configuration, application paths, and user settings. This guide provides a comprehensive reference for commonly used Windows environment variables, helping developers and system administrators understand their purpose and usage.
Commonly Used Windows Environment Variables
Variable | Description |
---|---|
%ALLUSERSPROFILE% |
C:\ProgramData |
%APPDATA% |
C:\Users\USERNAME\AppData\Roaming |
%COMMONPROGRAMFILES% |
C:\Program Files\Common Files |
%COMMONPROGRAMFILES(X86)% |
C:\Program Files (x86)\Common Files |
%COMSPEC% |
C:\Windows\System32\cmd.exe |
%HOMEDRIVE% |
C:\ |
%HOMEPATH% |
C:\Users\USERNAME |
%LOCALAPPDATA% |
C:\Users\USERNAME\AppData\Local |
%LOGONSERVER% |
\DOMAIN_LOGON_SERVER |
%PATH% |
Specifies the search path for executable files. Example: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem |
%PATHEXT% |
Defines the file extensions that the operating system treats as executable. Example: .com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc |
%PROGRAMDATA% |
C:\ProgramData |
%PROGRAMFILES% |
C:\Program Files |
%PROGRAMFILES(X86)% |
C:\Program Files (x86) |
%PROMPT% |
Defines the command prompt string. Example: $P$G |
%SYSTEMDRIVE% |
C: |
%SYSTEMROOT% |
C:\Windows |
%TEMP% |
Specifies the directory for temporary files. Example: C:\Users\USERNAME\AppData\Local\Temp |
%TMP% |
Same as %TEMP%. Example: C:\Users\USERNAME\AppData\Local\Temp |
%USERDOMAIN% |
Userdomain associated with current user. |
%USERDOMAIN_ROAMINGPROFILE% |
Userdomain associated with roaming profile. |
%USERNAME% |
The name of the current user. |
%USERPROFILE% |
The root directory of the current user's profile. Example: C:\Users\USERNAME |
%WINDIR% |
C:\Windows |
%PUBLIC% |
C:\Users\Public |
%PSMODULEPATH% |
Specifies the path for PowerShell modules. Example: %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\ |
%ONEDRIVE% |
C:\Users\USERNAME\OneDrive |
%DRIVERDATA% |
C:\Windows\System32\Drivers\DriverData |
%CD% |
Outputs current directory path. (Command Prompt.) |
%CMDCMDLINE% |
Outputs command line used to launch current Command Prompt session. (Command Prompt.) |
%CMDEXTVERSION% |
Outputs the number of current command processor extensions. (Command Prompt.) |
%COMPUTERNAME% |
Outputs the system name. |
%DATE% |
Outputs current date. (Command Prompt.) |
%TIME% |
Outputs time. (Command Prompt.) |
%ERRORLEVEL% |
Outputs the exit status of the previous command. (Command Prompt.) |
%PROCESSOR_IDENTIFIER% |
Outputs processor identifier. |
%PROCESSOR_LEVEL% |
Outputs processor level. |
%PROCESSOR_REVISION% |
Outputs processor revision. |
%NUMBER_OF_PROCESSORS% |
Outputs the number of physical and virtual cores. |
%RANDOM% |
Outputs random number from 0 through 32767. |
%OS% |
Indicates the operating system. Example: Windows_NT |
Managing Environment Variables
Environment variables can be viewed and modified through the System Properties dialog in Windows. You can set system-wide variables (affecting all users) or user-specific variables (affecting only the current user). Understanding how to manage these variables is essential for troubleshooting software installation issues, configuring development environments, and customizing system behavior.
Importance in Development
For developers, environment variables are critical for managing configuration settings, API keys, database credentials, and paths to executables or libraries. Tools and scripts often rely on these variables to locate necessary resources or adapt their behavior based on the execution environment. Properly setting and utilizing environment variables can significantly improve the portability and security of applications.
For more in-depth information on environment variables and their management in Windows, refer to the official Microsoft documentation.