[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

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
0
OCUBE
Asked:
OCUBE
  • 3
  • 2
  • 2
  • +2
1 Solution
 
OCUBEAuthor Commented:


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


0
 
Bill PrewCommented:
You can do this with the SETX command from the command line.

http://technet.microsoft.com/en-us/library/cc755104%28WS.10%29.aspx

~bp
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
netcmhCommented:
I concur with billprew: http://ss64.com/nt/setx.html
0
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
I agree, Bill Prew's Answer is the correct one.
0
 
QlemoC++ DeveloperCommented:
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.
0
 
netcmhCommented:
good point
0
 
Bill PrewCommented:
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.

~bp
0
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
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.

~Q
0
 
OCUBEAuthor Commented:

Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now