中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 12:06
47,811 topics / 349,897 posts / today 0 new / 48,255 members
DOS批处理 & 脚本技术(批处理室) » How to modify the PATH variable and make it take effect immediately? (Solved)
Printable Version  1,833 / 14
Floor1 tireless Posted 2008-01-02 20:25
银牌会员 Posts 1,122 Credits 2,025
The answer is in post #9

[ Last edited by tireless on 2008-5-26 at 06:40 PM ]
Floor2 lxmxn Posted 2008-01-02 20:46
版主 Posts 4,938 Credits 11,386
It should work inside the script, but after the script closes it won't work the next time. You could try writing to the registry...
Floor3 HAT Posted 2008-01-02 20:54
版主 Posts 5,017 Credits 9,023
Floor4 tireless Posted 2008-01-02 21:12
银牌会员 Posts 1,122 Credits 2,025
Originally posted by HAT at 2008-1-2 12:54 AM:



I had tried this before, but it doesn't take effect immediately.

[ Last edited by tireless on 2009-7-11 at 06:18 ]
Floor5 everest79 Posted 2008-01-02 21:49
金牌会员 Posts 1,127 Credits 2,564
Use call or start to create a new process
Floor6 lxmxn Posted 2008-01-02 21:50
版主 Posts 4,938 Credits 11,386
Originally posted by tireless at 2008-1-2 21:12:



I had tried this before, but it doesn't take effect immediately. If I enter set at the command line, I still can't see any change...

You probably need to restart cmd. If that doesn't work, restart explorer.exe. If that still doesn't work, restart computer.^_^
Floor7 everest79 Posted 2008-01-02 21:56
金牌会员 Posts 1,127 Credits 2,564
I haven't tried the registry method. This is how I use it.
http://www.cn-dos.net/forum/viewthread.php?tid=28204&fpage=1&highlight=%2Beverest79
Floor8 tireless Posted 2008-01-03 00:14
银牌会员 Posts 1,122 Credits 2,025
Floor9 vkill Posted 2008-01-03 17:19
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
wmic takes effect directly after modification

ENVIRONMENT - system environment settings management
::get the 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 the system environment variable home, value %HOMEDRIVE%%HOMEPATH%
wmic ENVIRONMENT create name="home",username="<system>",VariableValue="%HOMEDRIVE%%HOMEPATH%"
::delete the home environment variable
wmic ENVIRONMENT where "name='home'" delete
Floor10 tireless Posted 2008-05-27 13:36
银牌会员 Posts 1,122 Credits 2,025

::change the value of the path environment variable, add e:\tools
wmic ENVIRONMENT where "name='path' and username='<system>'" set VariableValue="%path%;e:\tools"


It seems the ; should be removed. If you don't remove it, there will be two ; after the modification.
Floor11 HAT Posted 2008-05-27 13:45
版主 Posts 5,017 Credits 9,023
Originally posted by tireless at 2008-5-27 01:36 PM:


It seems the ; should be removed. If you don't remove it, there will be two ; after the modification.

That depends on whether your %path% ends with a semicolon before the modification.
I suggest not removing this semicolon.
One extra semicolon doesn't matter.
But if one is missing, it will cause an error.
Floor12 tireless Posted 2008-05-27 14:08
银牌会员 Posts 1,122 Credits 2,025
@post #11
No, my path does not end with a semicolon, and a semicolon gets added automatically when it is modified. Why don't you try it

[ Last edited by tireless on 2008-5-26 at 06:13 PM ]
Floor13 HAT Posted 2008-05-27 17:12
版主 Posts 5,017 Credits 9,023
I tested it. Even if there is a semicolon in the wmic command, it still won't result in two semicolons in path.

Environment:
XP SP2 EN
path ends with a semicolon
Floor14 nafan Posted 2008-11-13 16:06
初级用户 Posts 21 Credits 22
OK, learned something new!
Floor15 hqso Posted 2008-11-13 16:40
初级用户 Posts 39 Credits 43
Really good, lots of colorful answers.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023