I was looking for a way to set the environment path variable with a .cmd file.
When the path variable was getting too long, I got some errors.
Just add the needed variables to 'Set Path variable' below
Check the current value of your path variable and add to the script
Run the script as administrator!
Open a new console window and it should work e.g. php -v
Asked
Active
Viewed 2.4e+01k times
73
Ruben
- 8,639
- 13
- 60
- 98
-
16I am afraid I don't understand the purpose of this topic. The "question" is not a question at all. It doesn't describe the problem nor the desired result, but include a "part of an answer" instead! On the other hand, the answer below seems to have no relation with the "question", so its usefulness its limited. The fact that the same person posted both parts is no excuse to bypass the question/answer format for topics on this forum... – Aacini Feb 06 '14 at 16:51
-
3Well it's just something I was looking for, and I could not find a decent answer, took me a long time to make this, so I added it as a community wiki so others can use it. Should I remove this? – Ruben Feb 07 '14 at 07:46
-
2nevermind, just use this tool: http://www.rapidee.com/en/about – Ruben Apr 30 '14 at 06:49
-
Possible duplicate of [Setting a system environment variable from a Windows batch file?](http://stackoverflow.com/questions/3803581/setting-a-system-environment-variable-from-a-windows-batch-file) – jww Jun 10 '15 at 06:27
1 Answers
108
@ECHO OFF
:: %HOMEDRIVE% = C:
:: %HOMEPATH% = \Users\Ruben
:: %system32% ??
:: No spaces in paths
:: Program Files > ProgramFiles
:: cls = clear screen
:: CMD reads the system environment variables when it starts. To re-read those variables you need to restart CMD
:: Use console 2 http://sourceforge.net/projects/console/
:: Assign all Path variables
SET PHP="%HOMEDRIVE%\wamp\bin\php\php5.4.16"
SET SYSTEM32=";%HOMEDRIVE%\Windows\System32"
SET ANT=";%HOMEDRIVE%%HOMEPATH%\Downloads\apache-ant-1.9.0-bin\apache-ant-1.9.0\bin"
SET GRADLE=";%HOMEDRIVE%\tools\gradle-1.6\bin;"
SET ADT=";%HOMEDRIVE%\tools\adt-bundle-windows-x86-20130219\eclipse\jre\bin"
SET ADTTOOLS=";%HOMEDRIVE%\tools\adt-bundle-windows-x86-20130219\sdk\tools"
SET ADTP=";%HOMEDRIVE%\tools\adt-bundle-windows-x86-20130219\sdk\platform-tools"
SET YII=";%HOMEDRIVE%\wamp\www\yii\framework"
SET NODEJS=";%HOMEDRIVE%\ProgramFiles\nodejs"
SET CURL=";%HOMEDRIVE%\tools\curl_734_0_ssl"
SET COMPOSER=";%HOMEDRIVE%\ProgramData\ComposerSetup\bin"
SET GIT=";%HOMEDRIVE%\Program Files\Git\cmd"
:: Set Path variable
setx PATH "%PHP%%SYSTEM32%%NODEJS%%COMPOSER%%YII%%GIT%" /m
:: Set Java variable
setx JAVA_HOME "%HOMEDRIVE%\ProgramFiles\Java\jdk1.7.0_21" /m
PAUSE
Ruben
- 8,639
- 13
- 60
- 98
-
6Looks great! My collection of paths strewn across Windows variables and Emacs variables needed some cleaning up, and I will try this. Very educational for me, thanks! – Brady Trainor May 01 '14 at 02:58
-
Thank you, that is exactly what I was looking for. I wanted to ask you guys, why has JAVA_HOME setx instead of SET like it is in the previous Path variables ? Thank yo – rchrd Jul 22 '20 at 14:12
-
2@rchrd SET initiates a variable in the console, setx actually sets the variables in the windows environment variables. You could just set the string in setx PATH , but that would make it unreadable, and the string can get so long you'll get an error. – Ruben Jul 23 '20 at 16:08