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-06-25 10:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] How to modify the system path environment variable with batch processing View 21,857 Replies 31
Floor 16 Posted 2007-04-06 13:37 ·  中国 广东 深圳 宝安区 电信
初级用户
Credits 20
Posts 10
Joined 2007-04-06 06:20
19-year member
UID 84144
Gender Male
Status Offline
The information I've been searching for for a long time has finally started to come to light. The internet is really great.
Floor 17 Posted 2007-07-05 14:53 ·  中国 北京 歌华宽带
新手上路
Credits 2
Posts 1
Joined 2007-07-05 14:03
18-year member
UID 93217
Gender Male
Status Offline
Floor 18 Posted 2007-09-17 16:18 ·  澳大利亚 Telstra全球互联网服务网络
新手上路
Credits 2
Posts 1
Joined 2007-09-17 15:49
18-year member
UID 97627
Gender Male
Status Offline
I'm sorry! I'm a newbie! I plan to create a batch file. It needs to add J:\Lotus\Notes\Data to the current PATH. Is there any senior brother to help?

From J:\Domino\Data;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Support Tools\;C:\Program Files\QuickTime\QTSystem\
To
J:\Domino\Data;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Support Tools\;C:\Program Files\QuickTime\QTSystem\;J:\Lotus\Notes\Data
Floor 19 Posted 2007-12-01 22:04 ·  中国 广东 湛江 电信
新手上路
Credits 2
Posts 1
Joined 2007-12-01 21:43
18-year member
UID 104383
Gender Male
Status Offline
Good
Floor 20 Posted 2007-12-02 01:38 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Originally posted by next45 at 2007-9-17 04:18 PM:
Sorry! I'm a newbie! I plan to create a batch file. It needs to add J:\Lotus\Notes\Data to the current PATH. Is there any senior to help

From
J:\Domino\Data;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Support Tools\;C:\Program Files\QuickTime\QTSystem\
To
J:\Domino\Data;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Support Tools\;C:\Program Files\QuickTime\QTSystem\;J:\Lotus\Notes\Data

@echo off
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%path%;J:\Lotus\Notes\Data" /f
Floor 21 Posted 2007-12-04 01:09 ·  中国 浙江 杭州 联通
初级用户
Credits 42
Posts 17
Joined 2005-08-28 14:49
20-year member
UID 42027
Status Offline
```
@echo off
Set /p Paths=Enter the "Path" path you want to add, separate multiple paths with ";" :
Set Regfile=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
For /f "tokens=3" %%i in ('Reg Query "%Regfile%" /v path^|Find /i "REG_EXPAND_SZ"') Do Set Pathf=%%i
Reg add "%Regfile%" /v path /t REG_EXPAND_SZ /d %Pathf%;%Paths% /f>nul
```
Floor 22 Posted 2008-03-11 18:39 ·  中国 云南 昆明 电信
新手上路
Credits 2
Posts 1
Joined 2007-02-28 12:24
19-year member
UID 80402
Gender Male
Status Offline
Floor 23 Posted 2008-05-26 13:57 ·  中国 辽宁 联通
初级用户
Credits 44
Posts 20
Joined 2006-12-09 12:44
19-year member
UID 73048
Gender Male
Status Offline
Floor 24 Posted 2008-05-26 15:36 ·  中国 上海 杨浦区 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
Hey, in Java teaching, there are always people who mess up the path system variable, which causes many program loading problems. But after looking at setx for a long time, I find that it only has the replace function and no append function, which makes it a bit troublesome.
Floor 25 Posted 2008-07-04 19:51 ·  中国 上海 联通
新手上路
Credits 2
Posts 1
Joined 2008-07-04 19:10
17-year member
UID 121100
Gender Male
Status Offline
I'm also working on this problem and want to try setx. I've modified the environment variables with wimc but they can't take effect immediately.
Floor 26 Posted 2008-07-04 20:56 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Modifying environment variables with wmic can take effect immediately. Did you write the command incorrectly? Post it and let's see?
Floor 27 Posted 2008-07-06 16:04 ·  中国 广东 江门 联通
初级用户
Credits 42
Posts 13
Joined 2007-08-03 23:26
18-year member
UID 94610
Gender Male
Status Offline
1. Use pathman

pathman /rs "c:\123"
pathman /as "C:\WINDOWS\system32\qqq"

pathman /as J:\Lotus\Notes\Data

2. Use WMIC

WMIC /PRIVILEGES:ENABLE ENVIRONMENT where name='PATH' set VariableValue="%PATH%;J:\Lotus\Notes\Data"
Floor 28 Posted 2008-10-22 08:29 ·  中国 广东 深圳 电信
新手上路
Credits 1
Posts 1
Joined 2008-10-22 08:05
17-year member
UID 129006
Gender Male
Status Offline
I used to use reg add/delete to modify the registry (in bat scripts) to add or delete environment variables before, but I found that after adding them, they don't take effect immediately and I need to restart the OS. I wonder if there is a way without restarting the OS.
Floor 29 Posted 2008-10-22 09:48 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
```
wmic ENVIRONMENT where "name='path' and username='<system>'" set VariableValue="%path%;C:\test"
```
Floor 30 Posted 2008-10-22 09:54 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
I used to use reg add/delete to modify the registry (in a bat script) to add or delete environment variables, but I found that after adding them, they don't take effect immediately and require a system restart. I wonder if there is a method that doesn't require restarting the OS.


You can use the command-line tool NirCmd to refresh the environment variables:
NirCmd sysrefresh environment

Or use a tool to modify environment variables, such as pathman
http://upload.cn-dos.net/img/989.rar
Forum Jump: