Configuring PATH and other environment variables in a bat file on Windows 7

from http://edeustace.wordpress.com/2010/09/19/configuring-path-and-other-environment-variables-in-a-bat-file-on-windows-7/

On Mac/Linux you can configure your environment variables easily by editing the ~/.bash_profile or the .bashrc file.

However in Windows one normally launches the Control Panel > System > Advanced System Settings, go to the Advanced tab then click the “Environment Variables…” button.

The downside of of this is that the input field provided by windows is very small which is a problem when you are editing the PATH variable. One usually has to copy the value out to a text editor, edit it the paste it back in.

I was helping a colleague configure his environment and I noticed that he was configuring his variables in a bat file. I have since left the project so I’m not sure how he was doing it. I’ve come up with my own solution here.

Basically the solution is:
1. Create a bat file
2. Add a shortcut to this bat file the start up items folder
3. In the bat file use the “setx” command

So I have a bat file here: c:\config\environment.variables.bat
I put a shortcut to it into: C:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Then this file looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
set PHP=C:\PHP5.3.3\
set PERL=C:\Perl64\site\bin
set PERL64=C:\Perl64\bin
set IMAGE_MAGICK=C:\Program Files (x86)\ImageMagick-6.5.6-Q8
set IMAGE_MAGICK16=C:\Program Files (x86)\ImageMagick-6.6.3-Q16
set RUBY=C:\Ruby187\bin
set RUBY2=%RUBY_HOME%\bin
set GRAILS=%GRAILS_HOME%\bin
set ANT=%ANT_HOME%\bin
set M2=%M2_HOME%\bin
set ROOT=%SystemRoot%\system32
set WBEM=%SystemRoot%\System32\Wbem
set POWERSHELL=%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
set SVN=C:\Program Files\SlikSvn\bin\
set PERFORCE=C:\Program Files\Perforce
set TOMCAT=%TOMCAT_HOME%\bin
set MYSQL=C:\Program Files\MySQL\MySQL Server 5.1\bin
set GIT=C:\Program Files (x86)\Git\cmd
set QUICKTIME=C:\Program Files (x86)\QuickTime\QTSystem\
set SBT=C:\Users\eeustace\dev\lift\sbt

setx PATH "%PHP%;%PERL%;%PERL64%;%IMAGE_MAGICK%;%IMAGE_MAGICK16%;%RUBY%;%RUBY2%;%GRAILS%;%ANT%;%M2%;%ROOT%;%WBEM%;%POWERSHELL%;%SVN%;%PERFORCE%;%TOMCAT%;%MYSQL%;%GIT%;%QUICKTIME%;%SBT%"

As you can see I’m using this to configure my PATH variable, but I could easily configure the other environment variables also.

Setx is a command in windows 7 that allows you to configure environment variables. More info here.

What do you think – useful?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值