China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-10 11:02
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to modify the PATH variable and make it take effect immediately? (Solved) View 1,832 Replies 14
Original Poster Posted 2008-01-02 20:25 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
The answer is in post #9

[ Last edited by tireless on 2008-5-26 at 06:40 PM ]
Floor 2 Posted 2008-01-02 20:46 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
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...
Floor 3 Posted 2008-01-02 20:54 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Floor 4 Posted 2008-01-02 21:12 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
Originally posted by HAT at 2008-1-2 12:54 AM:
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%path%;c:\test" /f



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

[ Last edited by tireless on 2009-7-11 at 06:18 ]
Floor 5 Posted 2008-01-02 21:49 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Use call or start to create a new process
Floor 6 Posted 2008-01-02 21:50 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
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.^_^
Floor 7 Posted 2008-01-02 21:56 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
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
Floor 8 Posted 2008-01-03 00:14 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
Floor 9 Posted 2008-01-03 17:19 ·  中国 甘肃 平凉 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
tireless +4 2008-01-03 17:52
Floor 10 Posted 2008-05-27 13:36 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline

::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.
Floor 11 Posted 2008-05-27 13:45 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
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.
Floor 12 Posted 2008-05-27 14:08 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
@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 ]
Floor 13 Posted 2008-05-27 17:12 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
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
Floor 14 Posted 2008-11-13 16:06 ·  中国 北京 鹏博士BGP
初级用户
Credits 22
Posts 21
Joined 2008-11-13 13:44
17-year member
UID 130844
Gender Male
Status Offline
OK, learned something new!
Floor 15 Posted 2008-11-13 16:40 ·  中国 江苏 泰州 电信
初级用户
Credits 43
Posts 39
Joined 2008-11-13 12:52
17-year member
UID 130838
Gender Male
Status Offline
Really good, lots of colorful answers.
Forum Jump: