![]() |
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-11 07:48 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » [Closed] How to modify the system path environment variable with batch processing |
| Printable Version 22,208 / 31 |
| Floor1 mylovelyqq | Posted 2006-11-25 09:59 |
| 初级用户 Posts 25 Credits 170 | |
|
Purpose: Modify or add the system path environment variable. If there is c:\123 in the environment variable, delete it. If there is no %System32%\qqq, add that path.
I used regedit /e or reg export in batch to export the HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment key in the registry, but the exported path is in the following hexadecimal number form and has multiple lines: "ComSpec"=hex(2):25...... "Path"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\ 00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,3b,00,25,00,\ 53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,3b,00,25,\ ......... "FP_NO_HOST_CHECK"="NO" "OS"="Windows_NT" "PROCESSOR_ARCHITECTURE"="x86" ........ Asking experts: 1. How to only keep the path key in the exported registry key (keep multiple lines completely) 2. How to modify the existing path and add a new path Note: The path obtained by set path in cmd is all absolute paths, not relative paths in the registry. I want to get relative paths, and absolute paths seem unable to be imported into the registry to change the path value. [ Last edited by HAT on 2008-10-22 at 09:48 ] |
|
| Floor2 redtek | Posted 2006-11-25 11:54 |
| 金牌会员 Posts 1,147 Credits 2,902 | |
|
The content queried by REG QUERY is not in hexadecimal.
You might as well use REG QUERY to query, and save the queried content into a file (redirect or use For), Isn't this an existing ASCII code? Why must you have that hexadecimal encoded registry content? Haha... |
|
| Floor3 mylovelyqq | Posted 2006-11-25 13:13 |
| 初级用户 Posts 25 Credits 170 | |
| Floor4 electronixtar | Posted 2006-11-26 01:34 |
| 铂金会员 Posts 2,672 Credits 7,493 | |
|
path=%path%;D:\My_Path
|
|
| Floor5 vkill | Posted 2006-11-26 01:42 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
Originally posted by electronixtar at 2006-11-26 01:34: Hehe, I also add this to autoexec.bat |
|
| Floor6 mylovelyqq | Posted 2006-11-26 04:40 |
| 初级用户 Posts 25 Credits 170 | |
Originally posted by electronixtar at 2006-11-26 01:34 AM: Brothers on floor 4 and floor 5, you think too simply. After you run your batch file, take a look at the system's path environment variable. The added path is not saved at all, it's only effective within your batch file. Think it over carefully |
|
| Floor7 namejm | Posted 2006-11-26 06:21 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Modifying environment variables generally requires making changes in the registry. Since I'm not familiar with this either, I can only get it to this point. Please, experts in the registry step in and offer strong assistance.
|
|
| Floor8 vkill | Posted 2006-11-26 06:33 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
Originally posted by mylovelyqq at 2006-11-26 04:40: >>c:\autoexec.bat echo path %path%;c:\tools I use it like this all the time |
|
| Floor9 lxmxn | Posted 2006-11-26 07:13 |
| 版主 Posts 4,938 Credits 11,386 | |
|
### Adding System Environment Variables:
The values of environment variables need to be entered manually. The ones imported into the registry should be permanent. I don't know how many characters the system environment variables can hold. If it can hold relatively few, it might not be imported successfully. Hehe, I don't know either. ``` @echo off&setlocal enabledelayedexpansion :begin cls set/p path_=Please enter the path of the environment variable you want to add: if not defined path_ goto error for,/f,"skip=4 tokens=1,2,*",%%a,in,('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v Path'),do,( echo The current environment variable is: echo %%c echo; set/p yesno=Do you confirm to add "%path_%" to the system environment variable? / if /i "!yesno!"=="y" ( reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%%c;%path_%" /f ) goto :eof ) pause goto :Eof :error echo Input error, please enter again pause goto begin ``` |
|
| Floor10 mylovelyqq | Posted 2006-11-29 02:46 |
| 初级用户 Posts 25 Credits 170 | |
|
I'm not very familiar with the for command, but I used a small tool called strrpc 1.0 to perform text replacement on the value exported by reg query .../v Path, and it still achieved the goal.
|
|
| Floor11 redtek | Posted 2006-11-29 03:06 |
| 金牌会员 Posts 1,147 Credits 2,902 | |
|
Attachments setx.rar (25.38 KiB) |
|
| Floor12 ccwan | Posted 2006-11-29 03:19 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
Brother redtek is always so enthusiastic, heh heh...
I'm here to post some water ![]() |
|
| Floor13 vkill | Posted 2006-11-29 07:47 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
Writing to autoexec.bat is completely okay~ At least my test in 03 was good
|
|
| Floor14 mylovelyqq | Posted 2006-11-29 08:18 |
| 初级用户 Posts 25 Credits 170 | |
| Floor15 vkill | Posted 2006-11-29 08:23 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
Originally posted by mylovelyqq at 2006-11-29 08:18: Brother often modifies the path??? I usually set two paths and never worry about it again. I think it's okay. Hehe~ Personal preference |
|
| 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |