×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Troubleshooting

How to add Safe Mode choice to XP boot menu by markdmac
Posted: 12 Feb 06 (Edited 13 Feb 06)

markdmac's Handy Dandy Utility Scripts

By Mark D. MacLachlan, The Spiders Parlor
http://www.thespidersparlor.com


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.

CODE

'==========================================================================
'
' 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
'==========================================================================


Const ForReading = 1, ForWriting = 2, ForAppending = 8

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

Function WaitTime

    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.
  
Happy scripting.

Mark

Back to Microsoft: Windows FAQ Index
Back to Microsoft: Windows Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close