Tired of trying to hit F8 at just the right moment just to get to safe mode to troubleshoot a PC? Here is a handy little script that will modify the Boot.ini file for you to add a Safe Mode memory choice to your boot menu. The script will also ask you how many seconds you want to wait until the default choice is selected. The default setting is 30 seconds. I prefer to set that to 5 seconds to help speed up boot times.
Save the following code to a text file in notepad and save the file with a .VBS extension. Then double click the file to execute. If the script detects that Safe Mode is already configured it will exit without modifying the file.
'========================================================================== ' ' NAME: AddSafeModeBoot.vbs ' ' AUTHOR: Mark D. MacLachlan , The Spider's Parlor ' URL: http://www.TheSpidersParlor.com ' COPYWRITE (c) 2005 All Rights Reserved ' DATE : 2/12/2006 ' ' COMMENT: Adds Safe Mode choice to XP boot menu ' '========================================================================== ' MODIFICATIONS: 2/13/2006 Added support for setting timeout '==========================================================================
Set objFSO = CreateObject("Scripting.FileSystemObject") Set WshShell = CreateObject("Wscript.Shell") 'Find the System Drive where Boot.Ini will be found Set env = WshShell.environment("Process") SysDrive = env.Item("SystemDrive") BootIni = SysDrive & "\boot.ini"
'Remove file ReadOnly, Hidden, System File state If objFSO.FileExists(BootIni) Then WshShell.Run("cmd /c attrib.exe " & BootIni & " -r -h -s") End If
Set oTextStream = objFSO.OpenTextFile(BootIni) 'make an array from the data file BootIniTxt = Split(oTextStream.ReadAll, vbNewLine)
'First check if Safe Mode alredy configured and quit if so. For Each line In BootIniTxt If InStr(1,line,"Safe Mode") Then WScript.Echo "Safe Mode Already Configured" LockFile WScript.Quit End If Next 'OK, Now find where the Windows install is located and add the safe mode line. For Each line In BootIniTxt If InStr(1,line,"timeout") Then timeArray = Split(line,"=") timeOut = timeArray(0) & "= " & WaitTime line = timeOut End If
If InStr(1,line,"Windows XP") Then lineArray = Split(line,"=") SafeModeLine = lineArray(0) & "=" & Chr(34) & "Safe Mode" & Chr(34) _ & " /safeboot:minimal /sos /bootlog" line = line & vbCrLf & SafeModeLine End If Report = Report & line & vbCrLf Next 'Open Boot.ini for writing and write new text Set ts = objFSO.OpenTextFile (BootIni, ForWriting) ts.write Report ts.close WScript.Sleep 300 LockFile
Sub LockFile 'Return file to previous ReadOnly, Hidden, System File state If objFSO.FileExists(BootIni) Then WshShell.Run("cmd /c attrib.exe " & BootIni & " +r +h +s") End If End Sub
Answer = InputBox("How many seconds delay would you like to configure for boot selection?" _ & vbCrlf & "Enter only numbers!","Boot Wait?") If IsNumeric(Answer) Then WaitTime = Answer Else WaitTime End If End Function
I hope you have found this FAQ helpful. Please remember to vote on the FAQ. Your votes help others decide what information/advice is worth taking. I strive for nothing less than 10s. Before you vote, if you don't think this FAQ rates a 10 please provide feedback to me first. Also please check out my other FAQs in the vbscript forum forum329.