Tuesday, July 13, 2010

Automatically Boot into Safe Mode

This batch file will backup your current boot.ini file, then add two safe mode options to your boot.ini file.
One is the same you would get when pressing F8 and choosing Safe Mode, the other is the just the minimal safe mode with no logging or display of drivers.
Copy the text in the code block into Notepad and save the file on your desktop as addsafe.bat (Be sure to change the Save as Type box in Notepad's Save dialog to All Files)
Double click the file to add the Safe Mode options.
Double click again to remove them.

Code:
@Echo Off
SetLocal EnableDelayedExpansion
PushD %SystemDrive%\
If Not Exist boot.ini Echo Unable to locate the boot.ini file&Goto _End
Attrib -H -R -S boot.ini
If Exist boot.TO~ (
Attrib -H -R -S boot.TO~
Del Boot.ini
Ren boot.TO~ boot.ini>Nul
Echo Safe Mode options have been removed from the boot menu
Goto _End
) Else (
Copy boot.ini boot.TO~>Nul
Attrib +H +R +S boot.TO~
)
If Exist boot.tmp Del boot.tmp
For /F "Tokens=1,2 Delims==" %%I In (boot.ini) Do (
Set _line=%%I
If /I "%%I"=="default" Set _Def=%%J
If "!_line:~0,1!"=="[" (
>>boot.tmp Echo.%%I
) Else (
>>boot.tmp Echo.%%I=%%J
))
>>boot.tmp Echo.%_Def%="Windows XP Safe Mode (minimal)" /safeboot:minimal
>>boot.tmp Echo.%_Def%="Windows XP Safe Mode (F8)" /safeboot:minimal /sos /bootlog /noguiboot
Del boot.ini
Ren boot.tmp boot.ini
Echo Safe Mode options have been added to the boot menu
:_End
Attrib +H +R +S boot.ini>Nul
PopD
Pause

No comments: