The Computer Oracle

Setting and getting Windows environment variables from the command prompt?

Never forget a word again. Memorabit: https://memorab.it

This video is brought to you by Memorabit, an app that sends words, definitions and translations as reminders at unexpected moments, so they stay in memory. Built on cognitive science principles, without AI. Start free on web, iOS and Android:
iOS: https://apps.apple.com/it/app/memorabit/...
Android: https://play.google.com/store/apps/detai...
--------------------------------------------------
Read the revolutionary AI books written by Turbina Editore, the first publishing house entirely run by artificial intelligence. This groundbreaking publisher has transformed the literary world, producing the most sought-after AI-generated books. Start reading today at:
https://turbinaeditore.com/en/
--------------------------------------------------

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: RPG Blues Looping

--

Chapters
00:00 Setting And Getting Windows Environment Variables From The Command Prompt?
00:51 Accepted Answer Score 359
01:23 Answer 2 Score 50
01:40 Answer 3 Score 6
02:34 Answer 4 Score 1
03:12 Thank you

--

Full question
https://superuser.com/questions/79612/se...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows #commandline #environmentvariables

#avk47



ACCEPTED ANSWER

Score 359


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 setx command:

setx NEWVAR SOMETHING

setx is built into Windows 7, but for older versions may only be available if you install the Windows Resource Kit




ANSWER 2

Score 50


We can also use "setx var variable /M" to set the var to system environment variable level instead of user level.

Note: This command should be run as administrator.




ANSWER 3

Score 6


System variables can be set through CMD and registry For ex. reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH

All the commonly used CMD codes and system variables are given here: Set Windows system environment variables using CMD.

Open CMD and type Set

You will get all the values of system variable.

Type set java to know the path details of java installed on your window OS.




ANSWER 4

Score 1


I want to add that if you are using the /s parameter with setx in order to set environment variables on a remote computer, the "Remote Registry" service needs to be running on the target machine or else you will receive a "ERROR: The specified operation could not be completed."

(I have asked Microsoft to update their TechNet article on setx to include this information.)