Batch modify boot. ini

Source: Internet
Author: User

 

Article from Baidu Library

Wenku.baidu.com/view/c8471b1152d417eb62946d35.html


The boot. ini file is the file that stores the boot menu in Win2000, WINXP, and win2003 systems. Therefore, it is especially important for you to learn to edit the boot. ini file.

 
The following are the batch processing code I have sought advice and studied in various forums. I believe many of my friends need the following code.
I. Functional requirements: (I) add a startup Item
Modify timeout = 4 and add c: \ grldr = "Start grub4dos" (do not delete other existing boot menus when adding them)
(Ii) Delete a startup Item
Do not delete other existing boot menus when deleting them.

II. The Code is as follows:
(I) Add the startup Item "add directly": (this method will cause repeated addition)
@ Echo off REM remove various attributes of boot. ini
Attrib-a-s-h-R % systemdrive % \ Boot. ini> nul rem adds a new startup Item to boot. ini. It is added to the end by default.
Echo c: \ grldr = "Start grub4dos" >>% systemdrive % \ Boot. ini REM modify the default wait time of the Startup menu to 4 seconds
Bootcfg/timeout 4 REM restore various attributes of boot. ini
Attrib + A + S + H + R % systemdrive % \ Boot. ini> NUL
 
Add method of replacement
① Method of adding a replacement: (this method deletes other non-Windows Startup menus)
@ Echo off
Attrib-a-h-r-s c: \ Boot. ini> NUL
Echo [boot loader]> C: \ Boot. ini
Echo timeout = 4> C: \ Boot. ini
Echo default = multi (0) disk (0) RDISK (0) Partition (1) \ Windows> C: \ Boot. ini
Echo [operating systems]> C: \ Boot. ini
Echo multi (0) disk (0) RDISK (0) Partition (1) \ Windows = "Microsoft Windows XP Professional"/noexecute = optin/fastdetect> C: \ Boot. ini

Echo c: \ grldr = "Start grub4dos"> C: \ Boot. ini
Attrib + A + H + R + s c: \ Boot. ini> NUL
 
② Method for adding a replacement: (this method is good and will not be added again .)
@ Echo off
Rem releases various attributes of boot. ini
Attrib-a-h-r-s c: \ Boot. ini> NUL
Rem saves boot. ini as boot. Bak
Type C: \ Boot. ini> C: \ Boot. Bak
Rem replaces the content of boot. ini with the first line of boot. Bak.
Type C: \ Boot. Bak | find "Boot Loader"/I> C: \ Boot. ini
The default waiting time for the REM added boot menu is 4 seconds.
Echo timeout = 4> C: \ Boot. ini
Rem displays the content of boot. Bak, but does not display the line containing boot loader and timeout, and adds the content to the content of boot. ini.
Type C: \ Boot. Bak | find "Boot Loader"/I/v | find "timeout"/I/V> C: \ Boot. ini
Rem adds the new boot item to boot. ini.
Echo c: \ grldr = "Start grub4dos"> C: \ Boot. ini
Rem restores various attributes of boot. ini
Attrib + A + S + R + H c: \ Boot. ini> NUL
 
③ Method for adding replacement: (this method will cause repeated addition)
@ Echo off
Set n = 0
Setlocal enabledelayedexpansion
For/F "delims =" % I in (c: \ Boot. INI) Do (
Set/a n + = 1
If not! N! Equ 2 (
Echo % I
) Else (
Echo timeout = 4
)
)> C: \ Boot. tmp
Echo c: \ grldr = "Start grub4dos"> C: \ Boot. tmp
Attrib-s-h-R "C: \ Boot. ini"
Copy "C: \ Boot. tmp" "C: \ Boot. ini"> NUL
Attrib + S + H + R "C: \ Boot. ini"
Del c: \ Boot. tmp> NUL
Pause> NUL
 
(Ii) Delete a startup Item
 
Using the bootcfg deletion method
 
① Direct deletion method: (assume that grub4dos and rdquo are started as the second startup Item)
@ Echo off REM remove various attributes of boot. ini attrib-a-s-h-R % systemdrive % \ Boot. ini> nul rem Delete the second startup Item

Bootcfg/delete/ID 2 REM restore various attributes of boot. ini
Attrib + A + S + H + R % systemdrive % \ Boot. ini> NUL
 
② Positioning and deletion method:
First, find the row number of the line where "Start grub4dos" is located and assign it to % target %. Then, find the row number of each "Start Project ID:" and assign it to % ID %, if the value is smaller than the target and is the largest % ID %, It is the ID of "Start grub4dos", and then delete it with bootcfg/delete/ID %.

@ Echo off
For/F "delims = [,]" % A in ('bootcfg/query ^ | find/I/N "Start grub4dos" ') do set target = %

For/F "delims = [,],: tokens = 1, 3" % A in ('bootcfg/query ^ | find/I/N "Start Project ID :"') do if % a lss % target % set/A id = % B

Bootcfg/delete/ID %
 
Replacement and deletion method
① First replacement and deletion method: @ echo off REM to remove various attributes of boot. ini
Attrib-a-s-h-R % systemdrive % \ Boot. ini> nul rem saves boot. ini as boot. Bak
Type % systemdrive % \ Boot. INI> % systemdrive % \ Boot. bak REM displays boot. the Bak content does not display the line containing & ldquo; Start grub4dos & rdquo;, and replaces the displayed content with boot. INI content.

Type % systemdrive % \ Boot. Bak | find "Start grub4dos"/I/V> % systemdrive % \ Boot. ini REM restore various attributes of boot. ini

Attrib + A + S + H + R % systemdrive % \ Boot. ini> nul rem deletes the temporary boot. Bak File
Del % systemdrive % \ Boot. Bak
 
② Replacement and deletion method: (this method is the simplest code)
@ Echo off
Type % systemdrive % \ Boot. ini> % systemdrive % \ Boot. Bak
Attrib-H-r-s % systemdrive % \ Boot. ini
Type % systemdrive % \ Boot. Bak | find "Start grub4dos"/I/V> % systemdrive % \ Boot. ini
Attrib + S + R + H % systemdrive % \ Boot. ini
 
③ Replacement and deletion method: (this method is cumbersome)
@ Echo off
Attrib-S-r-H % systemdrive % \ Boot. ini
If exist % systemdrive % \ boot2.iii del % systemdrive % \ boot2.iii
For/F "Skip = 2 tokens = * delims =$ $" % I in ('Find/V/I "Start grub4dos" C: \ Boot. INI ') Do echo % I> C: \ boot2.iii

Del % systemdrive % \ Boot. ini
Ren % systemdrive % \ boot2.iii boot. ini
Attrib + S + R + H % systemdrive % \ Boot. ini
Exit
 
 
Note: When you use bootcfg to add a startup Item 1. If you use copy, copy and> must be used before bootcfg; otherwise, copy and> will become invalid.

2.> and> NUL cannot be shared, otherwise> will be invalid.
3. before copying, you must remove the boot. ini attribute, that is, execute attrib-a-s-h-R % systemdrive % \ Boot. ini. Otherwise, copy will also become invalid. 4. When you use the bootcfg command to directly delete a startup Item, you must first determine which one to delete. Otherwise, deletion may occur.

 
 
■ ■ ■

 
After reading the help of bootcfg, there is indeed no option to add a custom switch. Change.exe, a third-party software recommended by climbing bamboo, has been used by Mao Tao and is indeed easy to use. However, I just want to try whether batch processing can be implemented without using third-party software.

Now you want to use batch processing to find
 
Multi (0) disk (0) RDISK (0) Partition (1) \ Windows = "Microsoft Windows XP Professional"/execute/fastdetect

 
This line, and can add strings at the end of this line, such as modifying
 
Multi (0) disk (0) RDISK (0) Partition (1) \ Windows = "Microsoft Windows XP Professional"/execute/fastdetect/kernel1_kernel.exe

 
The complete code is as follows:
 
: 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! & Amp; Goto: EOF
If exist % Temp % \ Boot. New del/f/A % Temp % \ Boot. New
Find/I "/kernel =" boot. ini> NUL & amp; echo modified boot. ini! & Amp; Goto: EOF

For/F "delims =" % L in (boot. INI) Do (
Echo. % L | find/I "/fastdetect"> NUL & amp; echo % L/kernel1_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! & Amp; Goto: EOF
Attrib-s-h-r boot. ini
Copy boot. ini % Temp % \ Boot. Bak> NUL & amp; 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 & amp; echo fail to wrtie boot. ini!

Attrib + S + H + r boot. ini
Del % Temp % \ Boot. New & amp; del % Temp % \ Boot. Bak
 
Code explanation:
For/F "delims =" % L in (boot. INI) Do (
Echo. % L | find/I "/fastdetect"> NUL & amp; echo % L/kernel1_kernel.exe | echo % L

)> Boot. New
 
The main function of this Code is to search for boot. for each line of the INI file, if/fastdetect is found, add the/kernel1_kernel.exe parameter to the end of the line, and save the file as boot. new, if the/fastdetect line is not found, the entire boot. the INI file is saved as boot. the new file is 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/kernel1_kernel.exe

Multi (0) disk (0) RDISK (0) Partition (1) \ WINNT = "Microsoft Windows 2000 Professional"/fastdetect/kernel1_kernel.exe

In this case, I think the landlord should see the difference. If no/fastdetect exists, the content of the boot. New file should be the same as that of the original boot. ini file.
 
 
Explanation: Echo. % L | find/I "/fastdetect"> NUL & amp; echo % L/kernel1_kernel.exe | echo % L

 
| Pipeline character, indicating that the output of the first command is used as the input of the second command, that is, the echo % I content is displayed as the find/I search content.
 
> NUL indicates that normal output is not displayed when this command is executed.
 
& Amp; indicates that if the preceding command is successfully executed, the subsequent statements are executed. If the execution fails, the subsequent statements are not executed.
 
| This indicates that this sentence will be executed if the previous statement fails. For example, if the/fastdetect character does not exist in the file, the echo % I will be executed, if all the preceding commands are successfully executed, we will not execute this sentence. Alas, typing is really tiring. That's all ...........

 
■ ■ ■

 
Modify the time in Boot. ini
 
@ Echo off
Title modify Start Menu time
Color FC
Mode con: Cols = 32 lines = 6
C:
CD \
Setlocal enabledelayedexpansion
 
Set boot = c: \ Boot. ini
For/F "tokens = 2 delims =" % I in ('findstr/C: "timeout" % boot % ') Do echo original Start Time: % I

 
Echo.
Echo, enter the desired start time, and press ENTER
Set/P times = changed:
Type boot. ini> boot. Bak
Attrib-H-r-s boot. ini
Type boot. Bak | find "Boot Loader"/I> boot. ini
Echo timeout = % times %> boot. ini
Type boot. Bak | find "Boot Loader"/I/v | find "timeout"/I/V> boot. ini
Attrib + S + R + H boot. ini
@ Del boot. Bak> NUL
 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.