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-07-31 22:33
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to write a script to automatically add system environment variables View 8,733 Replies 19
Floor 16 Posted 2006-12-27 22:56 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
After multiple experiments, it shows that: using AUTOEXEC.BAT can indeed add variables. The added variables are not written into the relevant items in the registry, and they also do not appear in the user and system variable lists in "My Computer". But these variables can play a role. After I added LANG=CHS in AUTOEXEC.BAT, Pro/E can change from the English version to the Chinese version, and changing LANG=EN can make it English. Haha, it's really interesting. After I added the SET PATH=E:\ACAD2000;E:\ACAD2000\Autodesk Shared; variable, my green AutoCAD no longer has prompts about not finding the path. This shows that the variables in autoexec.bat are indeed a good thing.
Floor 17 Posted 2006-12-28 01:23 ·  中国 北京 光环新网
新手上路
Credits 12
Posts 5
Joined 2006-12-27 08:04
19-year member
UID 74686
Gender Male
Status Offline
Thanks a lot, hunrybecky. I also succeeded in the test here.
Floor 18 Posted 2006-12-28 21:47 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
In the registry, whether PATH is sz or expand_sz depends specifically on the value of the environment variable.

If the environment variable has nested references to other environment variables, expand_sz must be used; otherwise, either can be used.

For issues with autoexec in XP, check previous posts.

http://www.cn-dos.net/forum/viewthread.php?tid=17155&fpage=1&highlight=
Floor 19 Posted 2006-12-28 22:38 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
Originally posted by qzwqzw at 2006-12-28 21:47:
In the registry, the PATH is either sz or expand_sz, specifically depending on the value of the environment variable

If the environment variable contains nested references to other environment variables, it must use expand_sz; otherwise, both are acceptable

xp 北...


According to brother's view, I checked some materials and compared the registry, and found that it doesn't seem very accurate. Microsoft's explanation is like this: REG_SZ represents a text string with a fixed length; while REG_EXPAND_SZ represents a data string with a variable length. This data type includes variables that are parsed when the program or service uses this data. See http://support.microsoft.com/kb/256986/.
According to Microsoft's explanation, then the paths used by programs or services should all use the REG_EXPAND_SZ type, but I set the user's environment variable TEMP to REG_SZ and it can still be parsed, so I'm a bit confused. Can anyone give a more complete and reasonable explanation?

Also, I compared these two types of data in the registry and found that generally fixed texts use REG_SZ, and as long as the path with %% variables is used, it uses REG_EXPAND_SZ. Maybe this is what is called fixed and non-fixed.
Floor 20 Posted 2006-12-28 22:42 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
Just now I found some more materials, and here's the explanation which is relatively reasonable:

REG_SZ
REG_SZ represents a simple text string. It is the most common data type in the registry. In the string editor dialog box, you can enter many types of information, such as names, paths, titles, or description texts, etc. REG_SZ can also be a number, for example, it can be used to represent RGB color codes or other types of information such as version numbers.

REG_EXPAND_SZ
Represents an expandable string. Its editor is similar to the standard REG_SZ string editor, but there are differences in variable usage. When entering variables in the REG_EXPAND_SZ editor, the system will treat it as a variable. When this variable is activated, the specific value of the variable will be displayed.
For example, "%SYSTEMROOT%" in the dialog box is a variable name. After activating it, it will return to the directory where Windows XP is located.
http://www.pcdog.com/book/html/20041025/25102004325_1.htm
Forum Jump: