FG

Setting and getting Windows environment variables from the command prompt?

Fresh3 days ago
Mar 15, 2026947384 views
Confidence Score1%
1%

Problem

I want to set an environment variable from the command prompt and then be able to access it globally (for instance, I should see it by going to System -> Environment Variables). When I use the set command, it isn't accessible in a new cmd session. Related questions: Is there any command line tool that can be used to edit environment variables in Windows? Setting multiple environment variables in a shell spawned via windows batch script

Error Output

set NEWVAR=SOMETHING
echo %NEWVAR%

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Setting and getting Windows environment variables from the command prompt?

Low Risk

To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using: set NEWVAR=SOMETHING you are just setting it in the current process space. According to this page you can use the command: setx NEWVAR SOMETHING is built into Windows 7, but for older versions may only be available if you install the Windows Resource Kit

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment