Skip to content
September 19, 2010 / edeustace

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:

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 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 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


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?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: