Windows: Environment Variables

Environment variables are named values that define the operating system environment. They are utilized by applications and system processes to access configuration information.

Characteristics:

  • Scope: System-wide or user-specific.
  • Usage: Referenced by applications and scripts.
  • Examples: PATH (stores system executable paths), TEMP (points to the temporary files directory).

Methods to Manage Windows Environment Variables:

MethodDescription
System PropertiesAccess: Control Panel > System > Advanced system settings > Environment Variables<br>- Type: System or User variables
Command Prompt (set command)Syntax: set VARIABLE_NAME=value<br>- Type: Temporary, affects current session.
Command Prompt (setx command)Syntax: setx VARIABLE_NAME value /M<br>- Type: Permanent, affects future sessions.<br>- Note: Requires a system restart for changes to take effect.
PowerShell (Get-Item & Set-Item)Syntax: Get-Item Env:VARIABLE_NAME / Set-Item Env:VARIABLE_NAME "value"<br>- Type: Temporary or Permanent.
Registry Editor (regedit)Path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment<br>- Type: Permanent.
Advanced System Settings GUIAccess: Control Panel > System > Advanced system settings > Environment Variables<br>- Type: System or User variables
Group Policy Editor (gpedit.msc)Path: Computer Configuration > Windows Settings > Environment<br>- Type: System-wide, affects all users.

Useful One-Liner Snippets
setx HOSTS "/drives/c/Windows/System32/drivers/etc" /m
setx HOSTS "/drives/c/Windows/System32/drivers/etc/hosts"
/msetx HOSTS "c:/Windows/System32/drivers/etc/hosts" /m

Leave a Reply

Your email address will not be published. Required fields are marked *