Batch setting system environment variables

Source: Internet
Author: User

While the software is running, you may need to configure your computer's environment variables, which can be divided into two scenarios:

One: Adding or modifying environment variables is only used in the current software environment

As we set the environment variables for Java:

Set classpath=%classpath%; C:\LS\JAVA. Jar
Keep the original unchanged and add the jar package to add, separated by semicolons, of course you can also write to the front, such as: Set classpath=d:/my_path;%classpath%
Set Java_home= the path here, write it for yourself.
But this write only for you to open the DOS window is valid, that is, you only in this window with Java and other commands, will find you only set the variable java_home, etc.
If you want to see if the settings are successful, use: Echo%java_home%

This method is commonly used to configure the current operating environment of the software, such as the start of PL/SQL, using batch (BAT) to start him and configure the Oracle variable information, the network of such code is not posted out, need to search for themselves.

II: Customs Clearance registry Permanent Save settings or increased environment variables

The following is the code I find from the Internet, very simple, if you do not understand, then give me a message:

instance one: Batch setting system environment variables

:: Add environment variable Java_home@echo offEchoAdd Java environment variable set Regpath=hkey_local_machine\system\currentcontrolset\control\session Manager\environmentset evname=Java_homeset Javapath=C:\java\jdkreg Add"%regpath%"/V%evname%/d%javapath%/Fpause>nul:: Delete environment variable Java_home@echo offEchoDelete Java environment variable set Regpath=hkey_local_machine\system\currentcontrolset\control\session Manager\environmentset evname=Java_homereg Delete"%regpath%"/V"%evname%"/Fpause>nul

Example Two: first determine if the environment variable is already present, and add the environment variable if it does not exist.

@echo off @set path_=D:\Program Files for,/F,"skip=4 tokens=1,2,*",%%a,inch,('reg QUERY "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session manager\environment"/V Path'), Do, (@set Pathall_=%%c)Echo%pathall_%|Find/I"%path_%"&& Set isnull=true|| Set isnull=false    ifNot%isnull%==true(reg add"hkey_local_machine\system\controlset001\control\session manager\environment"/V path/t reg_expand_sz/d"%pathall_%;%path_%"/f) Pause

For instance one and instance two is from the simple to the complex process, mainly is pats some people to the code understanding degree is different.

Batch setting system environment variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.