How to Set Up System Environment Variables in Windows
Set Windows environment variables permanently or for one session using Settings, PowerShell, Command Prompt, and safe PATH editing.
Short answer: Open Windows search, type environment variables, choose Edit the system environment variables, click Environment Variables, then add the value under User variables or System variables. User variables affect your account; System variables affect the machine and may require administrator permission. Open a new terminal or application after saving.
Choose the right environment-variable scope
| Scope | Lifetime | Who receives it | Typical use |
|---|---|---|---|
| Process | Current terminal or application only | That process and child processes | Temporary testing |
| User | Persistent across sessions and restarts | Your Windows account | Developer tools used by one account |
| Machine/System | Persistent across sessions and restarts | Users and processes on the computer | Shared tools or machine-wide configuration |
Windows processes inherit environment values from their parent process. An already-open terminal does not automatically receive values added later.
Method 1: Use the Environment Variables dialog
- Open Start and search for environment variables.
- Select Edit the system environment variables.
- In System Properties, open the Advanced tab and click Environment Variables.
- Under User variables for …, click New to configure your account only. Under System variables, click New for a machine-wide value.
- Enter the variable name, such as
MY_TOOL_HOME, and its value, such asC:\Tools\MyTool. - Click OK in each dialog.
- Close and reopen Command Prompt, PowerShell, or the application that needs the variable.
Microsoft documents this Control Panel workflow and the persistent User and System scopes in its environment-variable documentation.
Add a folder to PATH safely
In the Environment Variables dialog, select Path in the appropriate section, click Edit, choose New, and add one folder per entry, for example C:\Tools\MyTool\bin. Avoid replacing the entire existing value unless you have copied it first.
The graphical editor is the safest default for PATH. Microsoft warns that setx can truncate assignments longer than 1024 characters and can expand variable references in an existing value, which can damage a long PATH.
Method 2: PowerShell
Current PowerShell process only
$Env:MY_TOOL_HOME = 'C:\Tools\MyTool'
$Env:MY_TOOL_HOME
This changes only the current PowerShell process and programs launched from it.
Persistent User variable
[Environment]::SetEnvironmentVariable(
'MY_TOOL_HOME',
'C:\Tools\MyTool',
'User'
)
Persistent Machine variable
[Environment]::SetEnvironmentVariable(
'MY_TOOL_HOME',
'C:\Tools\MyTool',
'Machine'
)
Machine scope requires appropriate permission. Start PowerShell with the required elevation when your account is allowed to make machine-wide changes.
Read a variable and inspect its scope
$Env:MY_TOOL_HOME
[Environment]::GetEnvironmentVariable('MY_TOOL_HOME', 'User')
[Environment]::GetEnvironmentVariable('MY_TOOL_HOME', 'Machine')
Persist a User PATH entry with .NET
$name = 'Path'
$current = [Environment]::GetEnvironmentVariable($name, 'User')
$entry = 'C:\Tools\MyTool\bin'
$items = @($current -split ';' | Where-Object { $_ -and $_ -ne $entry })
[Environment]::SetEnvironmentVariable($name, (($items + $entry) -join ';'), 'User')
Review the existing value before changing PATH. If the value is managed by your organization or contains complicated expansion references, use the graphical editor instead.
Method 3: Command Prompt
Current window only
set MY_TOOL_HOME=C:\Tools\MyTool
echo %MY_TOOL_HOME%
Persistent value for future windows
setx MY_TOOL_HOME "C:\Tools\MyTool"
Persistent machine value
setx MY_TOOL_HOME "C:\Tools\MyTool" /m
setx writes a persistent value for future command windows; it does not update the current window. Microsoft states: “Variables set with setx variables are available in future command windows only, not in the current command window.” See the setx reference for syntax and limitations.
Do not routinely use setx PATH ... to append a directory. Its length limit and expansion behavior can corrupt PATH. Use the Environment Variables dialog or carefully managed PowerShell/.NET code.
Verify the change
PowerShell
$Env:MY_TOOL_HOME
Get-Command mytool
Command Prompt
echo %MY_TOOL_HOME%
where mytool
Application verification
- Close the terminal or application that was open during the change.
- Open a new terminal or restart the application.
- Print the variable from that new process.
- For PATH entries, run
where.exe program-nameor the program’s version command.
Common problems and fixes
| Symptom | Cause | Fix |
|---|---|---|
| The terminal shows the old value | Existing processes keep their inherited environment. | Open a new terminal or restart the application. |
| PowerShell assignment was not permanent | $Env:NAME = 'value' changes only the current process. |
Use SetEnvironmentVariable(..., 'User') or the dialog. |
setx value is missing now |
setx affects future command windows only. |
Open a new Command Prompt or PowerShell session. |
| Access denied for Machine scope | Machine variables require suitable permission. | Use User scope or run an authorized elevated session. |
| A command is still not found | The wrong folder was added, PATH was edited in the wrong scope, or the process is old. | Check the exact executable directory, inspect User and Machine PATH, then restart the terminal. |
| PATH entries disappeared or changed | A long setx PATH assignment may have been truncated or variable references expanded. |
Restore PATH from a backup or managed configuration and edit it with the dialog. |
| A value contains spaces | Command-line parsing split the value. | Quote the value, for example setx MY_TOOL_HOME "C:\Program Files\Tool". |
| A script sees a different value than your terminal | The script may run under another user, service account, parent process, or scope. | Print the variable inside that process and configure the scope it actually uses. |
Operational guidance
- Use Process scope for experiments and secrets that should disappear when the process exits.
- Use User scope for personal developer tools and paths.
- Use Machine scope only when every relevant account or service needs the value.
- Keep values short and avoid putting credentials in scripts, command history, or shared machine variables.
- Record the old PATH before editing it so you can restore an accidental change.
- After changing a value, restart programs that depend on it; services may also need a service restart.
Or skip the browser setup
If your goal is to capture a website image while automating Windows tasks, ScreenshotNeo provides a website screenshot API and MCP server. One request returns a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Cookie banners, newsletter popups, and chat widgets are removed before the shot. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing result. The MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The Free plan includes 1,000 screenshots each month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.
FAQ
Are environment variables case-sensitive on Windows?
Windows environment-variable names are conventionally written in uppercase. Use one consistent spelling in scripts and documentation.
Should I choose User or System?
Choose User when only your account needs the value. Choose System when machine-wide processes need it and you have permission to configure it.
Why does a child program see the variable?
Child processes inherit the environment of the process that launches them. A program started before the change cannot inherit a value that did not exist in its parent.
Can I make a temporary variable without changing Windows settings?
Yes. Assign $Env:NAME in PowerShell or use set NAME=value in Command Prompt. The value ends with that process.
What is the safest way to edit a long PATH?
Use the Environment Variables dialog and add or remove individual entries. Avoid a blind setx PATH ... replacement.


