Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set windows environment variables with a batch file

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

like image 293
Ruben Avatar asked Feb 06 '14 15:02

Ruben


People also ask

How do I set environment variable in CMD?

To set an environment variable, use the command " export varname=value ", which sets the variable and exports it to the global environment (available to other processes). Enclosed the value with double quotes if it contains spaces. To set a local variable, use the command " varname =value " (or " set varname =value ").

Can you use variables in batch files?

There are two types of variables in batch files. One is for parameters which can be passed when the batch file is called and the other is done via the set command.

How do I permanently set environment variables in Windows?

In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable. Click Edit to modify an existing environment variable.

What is %% in a batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


Video Answer


1 Answers

@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 
like image 110
Ruben Avatar answered Oct 07 '22 07:10

Ruben