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-14 23:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed]How to use batch processing to modify the parameters of the boot item in Boot.ini View 7,458 Replies 31
Original Poster Posted 2006-06-07 23:38 ·  中国 江苏 扬州 电信
初级用户
Credits 44
Posts 14
Joined 2006-06-07 21:18
20-year member
UID 56712
Status Offline
For example, my BOOT.INI is like this


timeout=1
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS

multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /execute /fastdetect
C:\Avldr.bin="Windows XPE By: Lao Maotao"
C:\GRLDR="GRUB Boot"

Now I want to use a batch script to find the line

multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /execute /fastdetect
And be able to add a string at the end of this line. For example, modify it to

multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /execute /fastdetect /Kernel=Kernel.exe
I'm a newbie, I sincerely ask all experts for your advice, and I hope you don't laugh at me.

[ Last edited by willsort on 2006-6-10 at 22:48 ]
Floor 2 Posted 2006-06-08 01:00 ·  中国 河北 保定 移动
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Worry-free Lao Maotao? Hehe, the world is too small.

But before posting for help, it's still recommended that you first read the forum rules. At least make it clear about the running environment of your batch script.

The simple method (I usually only use simple methods, my brain can't handle complicated ones) is that you can download a third-party DOS software called change.exe, and then study its usage (just type change /?).

The complicated one恐怕就要 use things like find, findstr, and also go through complicated other processing to complete the task. NND, if Microsoft provided a built-in sed, this thing would be too simple.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2006-06-08 01:07 ·  中国 河北 保定 移动
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Well, I suddenly thought that if the bootcfg command is flexibly run, it might make this operation simpler.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 4 Posted 2006-06-08 10:53 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re maotao:

The following code can be run in CMD to make corresponding modifications to boot.ini in the current path.

In addition, by roughly flipping through the help documentation of bootcfg, the useful switch /Addsw may only add a few limited fixed switches to boot.ini, and /kernel is not included in it.


@echo off
if exist boot.new del boot.new
if not exist boot.ini goto :eof
for /f "delims=" %%l in (boot.ini) do (
echo.%%l | find/i "/fastdetect">nul && echo %%l /kernel=kernel.exe||echo %%l
)>>boot.new
attrib -s -h -r boot.ini
copy boot.new boot.ini>nul
attrib +s +h +r boot.ini


[ Last edited by willsort on 2006-6-8 at 10:57 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 5 Posted 2006-06-08 11:17 ·  中国 浙江 杭州 电信
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Brilliant, really brilliant! Brother wil, I'm extremely佩服!
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 6 Posted 2006-06-08 14:03 ·  中国 江苏 苏州 电信
中级用户
★★
过度热情
Credits 321
Posts 139
Joined 2006-03-21 17:19
20-year member
UID 52521
Gender Male
Status Offline
"!!" example for /f %%i in (3.txt) do set str=!str!%%i As the question says!str! means the str variable, so why can't %str% be used.
"|", "||", "&", "&&" are often seen in batch processing. What are the specific functions? I'm a bit confused here. Muddled.!
Take the batch processing written by moderator willsort as an example: Please explain the mystery. The following batch processing is really classic喔.!
for /f "delims=" %%l in (boot.ini) do (
echo.%%l | find/i "/fastdetect">nul && echo %%l /kernel=kernel.exe||echo %%l
)>>boot.new
Floor 7 Posted 2006-06-08 15:23 ·  中国 江苏 苏州 电信
中级用户
★★
过度热情
Credits 321
Posts 139
Joined 2006-03-21 17:19
20-year member
UID 52521
Gender Male
Status Offline
Detailed Explanation of Batch Command Connectors and Pipes and Their Differences
up
Floor 8 Posted 2006-06-08 17:36 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
The main function of this code is to retrieve each line of the BOOT.INI file. If a line with "/fastdetect" is found, the parameter "/kernel=kernel.exe" is added after this line. Then, the file is saved as boot.new. If no line with "/fastdetect" is found, the entire content of the BOOT.INI file is saved as the boot.new file. As follows:

If the original BOOT.INI file is
[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(2)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect /kernel=kernel.exe
multi(0)disk(0)rdisk(0)partition(1)\WINNT="Microsoft Windows 2000 Professional" /fastdetect /kernel=kernel.exe
I think the building block should be able to see the differences. If there is no "/fastdetect", then the content of the boot.new file should be the same as the original BOOT.INI content.

Explanation: The sentence echo.%%l | find/i "/fastdetect">nul && echo %%l /kernel=kernel.exe||echo %%l

The | pipe character means that the output of the first command is used as the input of the second command, that is, the content of echo %%i is displayed as the content for find /i to search.

>nul means that the normal output of executing this command is not displayed

&& means that if the previous command is executed successfully, the subsequent statement is executed; if it is not executed successfully, the subsequent statement is not executed

|| means that if the executed statement fails, this sentence is executed. For example, if there is no line with the "/fastdetect" character in the file, then execute echo %%i. If the previous command is executed successfully, this sentence is not executed. Oh, typing is really tiring, that's probably all...

Go away in tears.............




Then after execution, it should be:
[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(2)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect
multi(0)disk(0)rdisk(0)partition(1)\WINNT="Microsoft Windows 2000 Professional" /fastdetect
Floor 9 Posted 2006-06-08 20:50 ·  中国 山西 临汾 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline

───────────────── Moderation Record ─────────────────
Performed by: Will Sort
Operation: Merge topic {21100} Batch Command Hunting Construction and Detailed Explanation of Their Differences -> Posts 6, 7, 8
Explanation: The operated topic has a direct contextual connection with this topic
Punishment: Deduct 8 points, including 6 points awarded for posting this topic and 2 points deducted for duplicate topic penalty
───────────────── Moderation Record ─────────────────
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 10 Posted 2006-06-10 21:15 ·  中国 江苏 扬州 电信
初级用户
Credits 44
Posts 14
Joined 2006-06-07 21:18
20-year member
UID 56712
Status Offline
Originally posted by Climbing at 2006-6-8 01:00:
Worry-free Laomaotao? Hehe, the world is too small.

But before posting for help, it is still recommended that you first read the forum rules, and at least make it clear about the running environment of your batch processing.

Simple method (I ...

Hehe, it's exactly me. Regarding the forum rules, I'm sorry, I'm a first-time visitor to the DOS Union and didn't read it clearly. There were people posting on the Worry-free forum asking for help regarding Boot.INI modification, so I rushed to post here for help. If there is any violation of the forum rules, please forgive me, moderator.
Originally posted by willsort at 2006-6-8 10:53:
Re maotao:

The following code can be run in CMD to complete the corresponding modification of boot.ini in the current path.

In addition, roughly flipping through the help document of bootcfg, there may be useful switches /Add ...

Thanks for the reply from Brother WillSort. I also flipped through the Bootcfg help, and indeed there is no option to add a custom switch. Regarding the third-party software change.exe recommended by Moderator Climbing. Laomaotao has used it, and it's really easy to use. But I just want to try, can batch processing achieve it without using third-party software.

Brother Will's code is concise and efficient, Laomaotao is deeply admired, and really needs to study hard. But can you be a good person to the end and help one more time, that is, if there is already /kernel=kernel.exe in the current system switch, how to handle it? I hope Brother Will will reply. In this regard, Laomaotao is not proficient at all, thank you first!
Floor 11 Posted 2006-06-10 22:03 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re maotao:

Regarding the issue of avoiding repeated modifications, adding a reverse find should work. The code is as follows. If there are any other corrections or requirements, feel free to continue pointing them out. Also, welcome brother to come here to exchange experiences with everyone.

The version management operation on floor 9 is for piziliu2004 on floor 6, which made you frightened :)


@echo off
if exist boot.new del boot.new
if not exist boot.ini goto :eof
for /f "delims=" %%l in (boot.ini) do (
echo.%%l | find/i "/fastdetect" | find /v /i "/kernel">nul && echo %%l /kernel=kernel.exe||echo %%l
)>>boot.new
attrib -s -h -r boot.ini
copy boot.new boot.ini>nul
attrib +s +h +r boot.ini
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 12 Posted 2006-06-10 22:08 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Adding a judgment statement based on the willsort code can meet the needs:

@echo off
if exist boot.new del boot.new
if not exist boot.ini goto :eof
for /f "delims=" %%l in (boot.ini) do (
echo.%%l | find /i "/kernel=kernel.exe">nul && goto :eof
echo.%%l | find /i "/fastdetect">nul && echo %%l /kernel=kernel.exe||echo %%l
)>>boot.new
attrib -s -h -r boot.ini
copy boot.new boot.ini>nul
attrib +s +h +r boot.ini


When replying, I found that willsort has already given a solution. Hehe, then I'll add some casual remarks and post it again.

[ Last edited by namejm on 2006-6-10 at 22:12 ]
Floor 13 Posted 2006-06-10 22:36 ·  中国 江苏 扬州 电信
初级用户
Credits 44
Posts 14
Joined 2006-06-07 21:18
20-year member
UID 56712
Status Offline
Originally posted by willsort at 2006-6-10 22:03:
Re maotao:

For the problem of avoiding repeated modifications, adding a reverse find should work. The code is as follows. If there are any other corrections or requirements, feel free to continue pointing them out. Also, welcome brother to come and...

Thanks to Brother Willsort for helping again. I think this time it can solve the problem for the friend who asked for help on Wuyou.

Hehe, just came to the DOS Union for the first time and got help from Brother Willsort. I'm very grateful! In the future, if there is any need for help with Lao Maotao, I won't be polite!
Floor 14 Posted 2006-06-11 16:54 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re maotao:

Because considering that the script needs to be applied to actual projects, and also the importance of boot.ini, so various operation links are considered as much as possible, and operation status judgment and prompts are added. Everyone can also check again whether the script has omitted some links that have not been processed.

It can be seen that this version of the script is much more complicated compared with the previous two versions, but the basic algorithm remains unchanged, which is the inevitable impact brought by code engineering.


:: ModBoot.cmd - V3 - Modify of boot.ini
:: Will Sort - 2006-6-11 - CMD@WinXP
@echo off
if not exist boot.ini echo Not found boot.ini!&goto :eof
if exist %temp%\boot.new del /f /a %temp%\boot.new
find/i "/kernel=" boot.ini>nul && echo Modified boot.ini! && goto :eof
for /f "delims=" %%l in (boot.ini) do (
echo.%%l | find/i "/fastdetect" >nul && echo %%l /kernel=kernel.exe || echo %%l
)>>%temp%\boot.new
find/i "/kernel" %temp%\boot.new>nul 2>nul
if errorlevel 1 echo Fail to parse boot.ini!&goto :eof
attrib -s -h -r boot.ini
copy boot.ini %temp%\boot.bak>nul&&echo Pass to backup boot.ini.
copy %temp%\boot.new boot.ini>nul 2>nul
find/i "/kernel" boot.ini>nul 2>nul
if not errorlevel 1 echo Pass to wrtie boot.ini.
if errorlevel 1 copy %temp%\boot.bak boot.ini>nul & echo Fail to wrtie boot.ini!
attrib +s +h +r boot.ini
del %temp%\boot.new & del %temp%\boot.bak
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 15 Posted 2006-06-13 00:35 ·  中国 江苏 扬州 电信
初级用户
Credits 44
Posts 14
Joined 2006-06-07 21:18
20-year member
UID 56712
Status Offline
Hehe, this is really an eye - opener, it's really good!
Forum Jump: