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 06:55
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please enter the batch code to determine which partition the system is installed on. Wait, no, the correct translation should be: How to use batch processing to determine which partition the system is installed on? View 2,452 Replies 11
Original Poster Posted 2006-11-23 02:26 ·  中国 陕西 安康 电信
初级用户
★★
Credits 171
Posts 78
Joined 2006-11-22 11:26
19-year member
UID 71373
Gender Male
Status Offline
For batch processing, I'm a layman. I saw the following code on Wuyou, which was originally given by a expert here.

The use of this code is to modify BOOT.INI when changing the XP boot screen. I tested it and it's very good.
@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

But there are also deficiencies. For multi - system, it will add /kernel=kernel.exe after /fastdetect. If you start to another system next time, it can't start. Also, the boot screens of 2000, XP, 2003 are different, and it can't judge the system.

I wonder if batch processing can be used to do the following points?
1. Judge whether it is the XP system. If yes, carry out the following operations. If not, give a warning and then exit.
2. If it is the XP system, judge which partition the system is installed in, and then modify the corresponding system in BOOT.INI.
3. When modifying, automatically add a startup item of the current system at the end.

I'm too bad to explain clearly. Give an example.
For example, under BOOT.INI is like this
[boot loader]
timeout=5
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows Server 2003, Standard Lite" /fastdetect
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Windows XP" /fastdetect

I just want to add something after multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Windows XP" /fastdetect. Can it be done?

Thank you for the answer.
Floor 2 Posted 2006-11-23 02:46 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
@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 "Windows XP" | 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
Floor 3 Posted 2006-11-23 02:56 ·  中国 陕西 安康 电信
初级用户
★★
Credits 171
Posts 78
Joined 2006-11-22 11:26
19-year member
UID 71373
Gender Male
Status Offline
Thanks to the moderator. But yours still can't solve this problem. If all the multi-systems are XP, then it will still add to each one. I am using the following to solve the partition problem. How to judge that the system is installed in partition(2), this is what I care about, that is, there are systems in several partitions. When modifying, I only want to modify the current (actually running) system's, and leave the others unchanged.

@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 "partition(2)\WINDOWS=" | 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
Floor 4 Posted 2006-11-23 08:04 ·  中国 陕西 安康 电信
初级用户
★★
Credits 171
Posts 78
Joined 2006-11-22 11:26
19-year member
UID 71373
Gender Male
Status Offline
Maybe my expression is not clear enough
Please help, everyone, can batch processing be used to complete this task
Floor 5 Posted 2006-11-23 08:29 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 6 Posted 2006-11-23 08:42 ·  中国 陕西 安康 电信
初级用户
★★
Credits 171
Posts 78
Joined 2006-11-22 11:26
19-year member
UID 71373
Gender Male
Status Offline
Suppose it is a hard disk, then how to judge the current system type and the partition where the system is located? Thanks.
Floor 7 Posted 2006-11-23 08:48 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
To determine the current system version, using the `ver` command is more accurate than looking for `boot.ini`. As for which partition the current system is installed on, using `%systemdrive%` or `%systemroot%` can accurately locate it. As for which record in `boot.ini` the current system corresponds to, it should not be difficult to get it using the `findstr` regular expression. Since I don't understand the meaning in `boot.ini`, I can only provide an idea for you.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 8 Posted 2006-11-23 09:02 ·  中国 陕西 安康 电信
初级用户
★★
Credits 171
Posts 78
Joined 2006-11-22 11:26
19-year member
UID 71373
Gender Male
Status Offline
Originally posted by namejm at 2006-11-22 07:48 PM:
  Judging the current system version, using the ver command is more accurate than finding boot.ini. As for which partition the current system is installed on, using %systemdrive% or %systemroot% can accurately locate it. As for 堮..

Thanks namejm, I often see your wonderful answers on Wuyou. Unfortunately, I know nothing about batch processing. The code I provided was also seen in the forum. Just love to tinker with XP systems. After testing this code, I found that it can replace manual work. But I think it's not perfect, so I raised the question
The /kernel in BOOT.INI means that when booting, the file specified after it is used to replace ntoskrnl.exe to initialize the system, and the file after = can be saved in system32. In this way, the personalized boot screen can be realized. The ntoskrnl.exe of different systems is different and cannot be general, so the above question is raised.
In addition, after modification, such as
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows Server 2003, Standard Lite Edition" /fastdetect /kernel=kernel.exe
It is better to change multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows Server 2003, Standard Lite Edition" /fastdetect to
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows Server 2003, Standard Lite Edition BAK" /fastdetect. In this way, in case of a bad modification, you can use this option to enter the system
Floor 9 Posted 2006-11-23 09:37 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
I searched online for introductions to boot.ini, and after slightly understanding the meanings of various entries inside, I found a shortcoming: it can only record the operating system version series such as 2K or XP, but does not record the language category of that version (that is, whether it is the Chinese version or the English version, etc.); in addition, the number in partition(1) indicates which partition it is, and it is also necessary to make a judgment corresponding to a certain partition with a certain serial number (it seems that the Nth partition is not necessarily the drive letter represented by the Nth letter, because I am not very familiar with the partition situation, I don't know if this statement is correct), it seems relatively difficult to achieve universality.

[ Last edited by namejm on 2006-11-22 at 08:38 PM ]
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 10 Posted 2006-11-23 10:00 ·  中国 陕西 安康 电信
初级用户
★★
Credits 171
Posts 78
Joined 2006-11-22 11:26
19-year member
UID 71373
Gender Male
Status Offline
Thanks namejm

In BOOT.INI, "partition" only represents a partition. "partition(1)" represents the first partition, and it has nothing to do with the letter (drive letter) because the drive letter can be re - designated in NT - based systems.
Floor 11 Posted 2006-11-23 10:12 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
If the partition is irrelevant to the drive letter, it will be very troublesome because %systemdrive% only gets the drive letter, not the partition number.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 12 Posted 2006-11-23 10:15 ·  中国 陕西 安康 电信
初级用户
★★
Credits 171
Posts 78
Joined 2006-11-22 11:26
19-year member
UID 71373
Gender Male
Status Offline
Originally posted by namejm at 2006-11-22 09:12 PM:
If the partition is irrelevant to the drive letter, then it's very troublesome, because %systemdrive% only gets the drive letter, not the partition number.


Thanks. It seems that it can't be solved universally. Thank you, all great experts. This post can be closed.
Forum Jump: