Batching, modifying the environment variable path method (plus environment variable)

Source: Internet
Author: User

Method one: In batch, modify environment variables, once valid (that is, in the current script is valid)

Run in cmd

Set path==%path%;d:/mypath

Use set path to view the current environment variables

Method Two: Batch processing, modify the environment variables, permanently valid

:: Change the value of the PATH environment variable, add E:\tools
WMIC environment where "name= ' path ' and username= ' <system> '" Set variablevalue= "%path%;e:\tools"

Also introduce some of the use of wminc (simple and practical)


:: Get TEMP environment variable
WMIC environment where "name= ' temp '" Get username,variablevalue
:: Add system environment variable home, value is%homedrive%%homepath%
WMIC environment Create Name= "Home", Username= "<system>", variablevalue= "%homedrive%%homepath%"
:: Delete Home environment variable
WMIC environment where "name= ' home '" delete
:: Get TEMP environment variable
WMIC environment where "name= ' temp '" Get username,variablevalue
:: Change the value of the PATH environment variable, add E:\tools
WMIC environment where "name= ' path ' and username= ' <system> '" Set variablevalue= "%path%;e:\tools"
:: Add system environment variable home, value is%homedrive%%homepath%
WMIC environment Create Name= "Home", Username= "<system>", variablevalue= "%homedrive%%homepath%"
:: Delete Home environment variable
WMIC environment where "name= ' home '" delete

In general, the system variables that WMIC creates or modifies do not have to be restarted windows to take effect, but if you find that the detection does not take effect under DOS windows, you try to close the DOS window and test it again. It's in effect.

If your batch does not want to close and let the new variable directly to the lower program application can write this


View Plaincopy to Clipboardprint?
:: Check if there is no e:\tools in path (jump to run, do not proceed)
echo%path%|findstr/i "E:\tools" && (Goto Run)

:: Add first to prevent error when not modified
WMIC environment Create Name= "path", variablevalue= "e:\tools;%path%"
:: Modify again to prevent errors that have sometimes been added
WMIC environment where "name= ' path ' and username= ' <system> '" Set variablevalue= "e:\tools;%path%"
:: Re-apply instantly
Set "path=e:\tools;%path%"

: Run
Start program. exe
:: Check if there is no e:\tools in path (jump to run, do not proceed)
echo%path%|findstr/i "E:\tools" && (Goto Run)

:: Add first to prevent error when not modified
WMIC environment Create Name= "path", variablevalue= "e:\tools;%path%"
:: Modify again to prevent errors that have sometimes been added
WMIC environment where "name= ' path ' and username= ' <system> '" Set variablevalue= "e:\tools;%path%"
:: Re-apply instantly
Set "path=e:\tools;%path%"

: Run
Start program. exe

Batching, modifying the environment variable path method (plus environment variable)

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.