|
ffo1984
新手上路

积分 6
发帖 2
注册 2006-10-24
状态 离线
|
『楼 主』:
怎么写一个自动完成系统环境变量添加的脚本
使用 LLM 解释/回答一下
我们公司有一个软件安装好后需要添加环境变量才能运行,因为数量太多,有点烦人,想写一个自动完成系统环境变量添加的脚本,有人会吗?
Our company has a software that needs to add environment variables to run after installation. Because there are too many, it's a bit annoying. I want to write a script to automatically complete the addition of system environment variables. Does anyone know how?
|
|
2006-10-24 22:21 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
2003/Vista下倒是有个 setx ,在XP下只能通过reg/regedit改注册表了。
Under 2003/Vista, there is a setx, but under XP, you can only change the registry through reg/regedit.
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-10-24 22:38 |
|
|
ffo1984
新手上路

积分 6
发帖 2
注册 2006-10-24
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
这样啊!谢谢哦!看来老兄们已将享受上新的操作系统了!
Oh, I see! Thanks! It seems that the guys have already enjoyed the new operating system!
|
|
2006-10-25 08:03 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
set path="c:\windows\help";%path%
其中"c:\windows\help"只是个示范,可以把很多路径加到里面,不过别忘了中间加上";"分隔每个路径。这样不能永久的设置环境变量,只能临时用一下。要使设置的环境变量长期有效,只有手工改一下系统环境变量了,或者修改注册表。
set path="c:\windows\help";%path%
Among them, "c:\windows\help" is just an example. You can add many paths to it, but don't forget to add ";" in the middle to separate each path. This can't set the environment variable permanently, it can only be used temporarily. To make the set environment variable effective for a long time, you can only manually modify the system environment variables or modify the registry.
|
|
2006-10-25 08:11 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2006-10-25 08:52 |
|
|
chenall
银牌会员
    
积分 1276
发帖 469
注册 2002-12-23 来自 福建泉州
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
使用VBS
dim wsh
Set wsh = WScript.CreateObject("WScript.Shell")
wsh.Environment("system").Item("<变量名>")="<值>"
或使用使用REG
set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
::系统环境变量
::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
::用户环境变量
::HKEY_CURRENT_USER\Environment
reg add "%regpath%" /v "<name>" /d "<data>"
将上面的<>内容替成你需要定义的名称和值就可以了.
Using VBS
dim wsh
Set wsh = WScript.CreateObject("WScript.Shell")
wsh.Environment("system").Item("<Variable Name>")="<Value>"
Or using REG
set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
::System environment variables
::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
::User environment variables
::HKEY_CURRENT_USER\Environment
reg add "%regpath%" /v "<name>" /d "<data>"
Just replace the content in <> with the name and value you need to define.
|

QQ:366840202
http://chenall.net |
|
2006-10-25 09:26 |
|
|
alucifer
新手上路

积分 12
发帖 5
注册 2006-12-27
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
如果我要给path设置值,怎么用reg add 加啊? 就是不改变path原有的值,加上我需要的值。
能写下具体怎么做么?
万分感谢!!
If I want to set the value of path, how to use reg add to do it? That is, without changing the original value of path, add the value I need. Can you write down specifically how to do it? Thanks a lot!
|
|
2006-12-27 08:25 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
path在注册表中为二进制表示,不是很好操作。
The path is represented as binary in the registry, which is not very easy to operate.
|
|
2006-12-27 21:24 |
|
|
alucifer
新手上路

积分 12
发帖 5
注册 2006-12-27
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
没有那么麻烦吧,就是象6楼说的,用:
set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
reg add "%regpath%" /v "Path" /d "<data>"
但是这样会覆盖Path原来的值。
我试了试这样写:
set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
set Path=<data>;%Path%
reg add "%regpath%" /v "Path" /d "%Path%"
但是出现 error : too many command-line .......
我的想法就是把原来的值倒出,修改后再导入,但是不熟悉dos命令。。。。
Is it that troublesome? Just as the 6th floor said, use:
set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
reg add "%regpath%" /v "Path" /d "<data>"
But this will overwrite the original value of Path.
I tried writing it like this:
set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
set Path=<data>;%Path%
reg add "%regpath%" /v "Path" /d "%Path%"
But there was an error: too many command-line .......
My idea is to export the original value, modify it and then import it back, but I'm not familiar with DOS commands...
|
|
2006-12-27 21:49 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
我找到一个非常好的方法。就是利用AUTOEXEC.BAT中的SET PATH。这个原理我不是很清楚,但是已经试验成功,我也觉得很奇怪。据说WINNT都不使用AUTOEXEC.BAT了,但事实并非如此,大家做一个小实验,看你们的电脑上能否成功。
追加PATH路径而不覆盖原有路径:如果你系统盘没有AUTOEXEC.BAT,那么就建立一个,在里面追加内容SET PATH=D:\;E:\;F:\;G:\;
重新启动电脑,奇迹出现了,使用set path查看下你的PATH变量吧,居然把AUTOEXEC.BAT中设置的变量添加到了PATH变量中。真是奇怪.
I found a very good method. That is to use SET PATH in AUTOEXEC.BAT. I don't know the principle very well, but it has been tested successfully, and I also feel very strange. It is said that WINNT doesn't use AUTOEXEC.BAT anymore, but the fact is not like that. Everyone do a small experiment to see if it can succeed on your computer.
Appending PATH paths without overwriting the original paths: If your system disk doesn't have AUTOEXEC.BAT, then create one, and append the content SET PATH=D:\;E:\;F:\;G:\; in it.
Restart the computer, and the miracle happens. Use set path to check your PATH variable, and it turns out that the variable set in AUTOEXEC.BAT is added to the PATH variable. It's really strange.
|
|
2006-12-27 22:16 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
试验成功的跟帖,上面的路径可以改变成任何自己需要的路径,但必须注意每个路径后必须使用;来分开.
Posts where the test is successful. The path above can be changed to any path you need, but you must pay attention that each path must be separated by a semicolon.
|
|
2006-12-27 22:17 |
|
|
alucifer
新手上路

积分 12
发帖 5
注册 2006-12-27
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
感谢hunrybecky, 但是真的无法通过修改注册表来添加Path吗?
期待帮助。。。。。
Thanks to hunrybecky, but is it really impossible to add Path by modifying the registry? Looking forward to help...
|
|
2006-12-27 22:23 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
能够,我开始也想到通过注册表来添加,但是想到因为是使用的可扩展的字符(更改我开始说的是二进制,最后查得知是可扩展字符串,抱歉),导出注册表的是长串的数字,所以就放弃了,而意外的发现刚才哪个利用AUTOEXEC.BAT的方法.现在使用注册表的方法也已经成功,实际上可扩展字符也不影响,直接使用一般的REG_SZ就可以了.方法补如下:
@ECHO OFF
SET SE=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
REG ADD "%SE%" /V Path /t REG_EXPAND_SZ /d %PATH%G:\ACCESS; /f
@ECHO ON
注意的是%SPATH%G:\ACCESS;注意原来的变量与添加的之间没有;
Yes, I also thought of adding it through the registry at first, but then I thought that because it's using expandable characters (I said binary at first, but later found out it's expandable string, sorry), the exported registry is a long string of numbers, so I gave up, and accidentally discovered the method of using AUTOEXEC.BAT just now. Now the method using the registry has also been successful. Actually, expandable characters don't affect, you can directly use the general REG_SZ. The method is as follows:
@ECHO OFF
SET SE=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
REG ADD "%SE%" /V Path /t REG_EXPAND_SZ /d %PATH%G:\ACCESS; /f
@ECHO ON
Note that %SPATH%G:\ACCESS; Note that there is no ; between the original variable and the added one
|
|
2006-12-27 22:30 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
XP应该是不会执行AUTOEXEC.BAT,却会解析AUTOEXEC.BAT中的一些变量,路径就是其中一个。
XP should not execute AUTOEXEC.BAT, but will parse some variables in AUTOEXEC.BAT, and the path is one of them.
|
|
2006-12-27 22:30 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by zh159 at 2006-12-27 22:30:
XP应该是不会执行AUTOEXEC.BAT,却会解析AUTOEXEC.BAT中的一些变量,路径就是其中一个。
是的,从这个例子可以说明兄的观点,而且更有意思的是,AUTOEXEC.BAT中设置的变量是添加到现有的变量中而不是替代,所以利用这个东西,应该可以做很多有意思的事情了.
Originally posted by zh159 at 2006-12-27 22:30:
XP should not execute AUTOEXEC.BAT, but will parse some variables in AUTOEXEC.BAT, and the path is one of them.
Yes, from this example, it can illustrate your point, and what's more interesting is that the variables set in AUTOEXEC.BAT are added to the existing variables instead of replacing them, so using this thing, we should be able to do many interesting things.
|
|
2006-12-27 22:33 |
|