Application of Set and SETX commands

Source: Internet
Author: User

While the software is running, you may need to configure your computer's environment variables, where you can configure the Java environment variables as an example.
1. Set command: This syntax is only valid in a CMD shell environment, and shutting down the environment variables will not be saved.
Example:
[Plain] View plain copy @echo off set path=c:\java\jdk1.8.0_31\bin set/p cmd= "Environment variable setting is complete, enter Javac carriage return test:"%path% @pa Use


2. SETX command: Windows XP above the system comes with the command (if not, download a Setx.exe), this way to permanently set environment variables.
Setting User Environment variables
Setx path "C:\Java\jdk1.8.0_31\bin"

Setting System Environment variables

Setx path "C:\Java\jdk1.8.0_31\bin"/M note 1.
In some cases, the "SETX Invalid syntax default option cannot exceed the ' 2 '" error, which is believed to be caused by a space in the original environment variable, can be avoided using double quotation marks.
Note 2.
SETX the environment variable is set, it will take effect in the newly opened terminal and the current terminal will not take effect immediately.
Note 3.
Setx the length of the variable is more than 1024, it intercepts the extra characters.
Note 4.
SETX can also operate the remote computer, the specific parameters set Baidu Setx usage.
Note 5.
SETX sets the value of a variable that overwrites the previous value if it already exists. So the correct way is to save the value = Get the value of the current variable + new value.
Example: Set oldvalue= gets the current variable value
Setx Path%oldvalue%;%newvalue%
The following is a value that gets the user environment variable path, which reads the value in the registry.
[Plain] View plain copy @echo off set regpath= hkey_current_user\environment set Key=path:: Determine if the path is present in REG query %regpath%/V%key% 1>nul 2>nul if%errorlevel%==0 (:: Value for/f "tokens=3,4 delims="%%v in (' Reg Query%reg path%/V%key% ') do set oldvalue=%%v) else Set oldvalue= "" The original value of Echo%key% is:%oldvalue% pause

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.