Avatar of OCUBE
OCUBEFlag for United States of America asked on

How to set environmental variables in Windows 7 using a batch file ?

I have a Windows 7 PC and I wanted to set the environmental variables.

I know I can right click on MYCOMPUTER=> Advanced tab and set there SYSTEM EV.

But instead of doing that I wanted to write a windows batch file (.BAT) and do it.

How can I do that.

If i go to command line and use the SET command , is it only for that particular session, once we close and reopen another session the EV are no longer there.

I wanted to set the EV permanent, same way as what we do using GUI, but using a windows batch file (.bat).

Give me the commands or some sample script

Thanks in advance
Windows 7Microsoft DOS

Avatar of undefined
Last Comment

8/22/2022 - Mon


All  need to know is the command to setup the EV in command prompt and it should
be permanent, not just for that session.

Bill Prew

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

I concur with billprew: http://ss64.com/nt/setx.html
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Ben Personick (Previously QCubed)

I agree, Bill Prew's Answer is the correct one.

AFAIK there is still a difference between the GUI and setx: setx will not inform open Windows about the change. Usually that does not matter, since most applications ignore the change anyways until restarted, but sometimes it is important to know that.

good point
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Bill Prew

Well, there are some subtleties there, right.  For instance, if I set a system variable from the GUI, but had a command shell window open, that command shell doesn't see that new environment variable.

Ben Personick (Previously QCubed)

Agreed - on both Qlemo and BP's accounts there.. Though, I did think SETX had the same drawback with open windows as via GUI for other command windows, but haven't tested, I believe BP to know his stuff.

  Still, I imagine SETX wins out because he asked "From the Command Line", but as always; the author's true intentions for implementation may allow for the GUI method, or perhaps prefer it.


Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes