Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To create a persistent environment variable in Windows, open System Properties > Advanced > Environment Variables, then add it under User variables for your account or System variables for machine-wide configuration. For a temporary value, set it in the terminal session instead. Choose the scope before you edit: a value set in a terminal does not automatically become persistent, and a persistent change usually appears only in newly started programs.
Choose the right scope
An environment variable is a string a program can read, such as a directory path or a configuration value. Windows has three relevant scopes:
- Process: applies to the current process and its child processes. A change made in a terminal this way is temporary; closing the terminal ends that session.
- User: persists for the signed-in user and is appropriate when only that account needs the setting.
- Machine (System): persists as machine-wide configuration. Changing it can require administrator permission.
For most personal development setups, use a User variable. Use a System variable only when machine-wide availability is intended and you have permission to change it. Microsoft documents User and System values as persistent across sessions and restarts.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Set a persistent variable in Windows Settings
The Environment Variables dialog is the safest default for adding or editing a variable, especially when changing PATH.
#1 Best Overall
- Open Start and search for environment variables or Edit the system environment variables. You can also open the System Control Panel route, then select Advanced system settings.
- In System Properties, open the Advanced tab and select Environment Variables.
- In the upper section, User variables for [your account], choose New to add a user variable or select an existing variable and choose Edit.
- Enter the variable name and value. For example, name it
MY_TOOL_HOMEand set its value toC:ToolsMyTool. - Choose OK to close each dialog. If the value must be machine-wide, make the change in the lower System variables section instead; Windows may request administrator approval.
- Open a new terminal or application to check the value. Existing processes generally keep the environment they inherited when they started.
Use a clear variable name and enter the value without adding quotes unless the application that consumes it specifically requires quotes. The example path is illustrative; use the actual folder or value your software requires.
Set variables from PowerShell
PowerShell supports both a session-only assignment and persistent User or Machine values. These commands use the .NET environment-variable API for persistence:
# Current PowerShell process only
$Env:MY_TOOL_HOME = 'C:ToolsMyTool'
# Persistent for the current user
[Environment]::SetEnvironmentVariable('MY_TOOL_HOME', 'C:ToolsMyTool', 'User')
# Persistent machine-wide; requires appropriate permission
[Environment]::SetEnvironmentVariable('MY_TOOL_HOME', 'C:ToolsMyTool', 'Machine')
The first command changes the environment of the current PowerShell process; it does not by itself write a persistent User or Machine setting. Use User or Machine as shown when you want the setting to persist. A Machine-scope write needs appropriate permission, so run an elevated PowerShell session if Windows denies the operation.
After a persistent change, open a new PowerShell window and inspect the value:
Rank #2
$Env:MY_TOOL_HOME
In the same PowerShell session where you ran the persistent .NET method, do not assume its process environment has been refreshed. A new process is the reliable check.
Set a variable from Command Prompt
Temporary: current command window
Use set when the value is needed only in the current Command Prompt session and programs launched from it:
set MY_TOOL_HOME=C:ToolsMyTool
echo %MY_TOOL_HOME%
Persistent: future command windows
Microsoft documents setx for persistent values. The setting becomes available to future command windows, not the one in which you ran the command:
Recommended Free Tools
setx MY_TOOL_HOME "C:ToolsMyTool"
setx MY_TOOL_HOME "C:ToolsMyTool" /m
The first form writes a user variable; /m requests a system environment variable and may require an elevated Command Prompt. Start a new Command Prompt to verify it with echo %MY_TOOL_HOME%.
Rank #3
Do not use setx PATH ... as a routine way to append a directory. Microsoft warns that setx has a 1024-character assignment limit and truncates longer values. It also expands variable references in an existing value rather than preserving those references. Either behavior can damage PATH. Use the Environment Variables dialog to edit PATH, or use a carefully considered PowerShell/.NET approach after examining the existing value and scope.
Add a folder to PATH safely
PATH is the environment variable programs use to locate executable files in listed directories. If a tool’s installer asks you to add a folder to PATH, add the directory containing the executable—not the executable’s filename—and choose User or System scope according to who needs it.
- Open Environment Variables using the steps above.
- Select
Pathin the intended scope and choose Edit. - Add the tool’s directory as a separate entry, preserving the existing entries. Do not replace the whole value with the new directory.
- Confirm the dialogs and open a new terminal. Run the tool’s command or inspect the variable to verify that the new process sees the update.
Because PATH may already be long and may contain variable references, avoid copying it into a setx PATH command. If you choose to edit it with a script instead, first understand which scope you are changing and preserve the existing entries deliberately.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Verify the value and understand when it takes effect
Processes inherit environment values from their parent process. An already-open terminal, editor, service, or application does not automatically become a new process after you save a persistent setting. Close and reopen the program that needs the variable; if a newly opened terminal was launched from an older application, restart that application too.
Rank #4
| Where you are checking | Command | What it checks |
|---|---|---|
| Command Prompt | echo %MY_TOOL_HOME% |
The value visible to that Command Prompt process. |
| PowerShell | $Env:MY_TOOL_HOME |
The value visible to that PowerShell process. |
If the output is blank or unexpected, check that the variable name is spelled the same way in the application and in Windows, that you chose the intended scope, and that the terminal or application was started after the change.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting common problems
The current terminal cannot see my new persistent variable
That terminal may have started before the change. Open a new Command Prompt or PowerShell window and check again. Persistent values are for future processes; an existing process does not automatically refresh its inherited environment.
An application still cannot find a command after I changed PATH
Restart the application so it starts with the updated environment, then confirm that the PATH entry is the directory containing the executable. Check the User and System sections to ensure you edited the scope relevant to the process that needs it.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Windows refuses a Machine-scope change
System variables are machine-wide and may require elevated permission. If you do not have that permission or only your account needs the value, set it as a User variable instead.
Best Value
A PATH value looks cut off after using setx
setx can truncate an assignment longer than 1024 characters. It also expands variable references in existing values. Avoid repeating the command with the same long value; inspect the current PATH and repair it through the Environment Variables dialog, preserving the entries that remain. If a required entry was lost, add it back from the relevant software’s installation details.
A variable appears with unexpected literal text or a different value
Check for a typo in the variable name and confirm that the application is reading the scope you edited. When you use setx with a value based on an existing variable, remember that references may be expanded rather than retained as references. For a value needed only in one test session, a Process-scope assignment avoids changing persistent settings.
Or skip the browser setup
ScreenshotNeo is a separate option for developers who need website screenshots; it does not set Windows environment variables. Its API accepts a URL and returns a screenshot or PDF, and its documentation is at ScreenshotNeo API docs.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutecurl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture, with each step configurable. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed; responses identify the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. See ScreenshotNeo for the service and sign up for free to get 1,000 screenshots a month with no card.
Frequently Asked Questions
Can an environment variable contain a folder path?
Yes. A variable’s value is a string, so it can contain a path such as C:ToolsMyTool. Use the format expected by the program that reads it.
Do I need to restart Windows after setting a variable?
A restart is not usually needed just to make a persistent change available to newly started processes. Restart the terminal or application that needs the new value.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

