Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add Safe Mode choice to XP boot menu

Troubleshooting

How to add Safe Mode choice to XP boot menu

by  markdmac  Posted    (Edited  )
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:
[green]'==========================================================================
'
' 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
'==========================================================================[/green]

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

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("Wscript.Shell")
[green]
'Find the System Drive where Boot.Ini will be found[/green]
Set env = WshShell.environment("Process")
SysDrive = env.Item("SystemDrive")
BootIni =  SysDrive & "\boot.ini"



[green]'Remove file ReadOnly, Hidden, System File state[/green]	
If objFSO.FileExists(BootIni) Then
	WshShell.Run("cmd /c attrib.exe " & BootIni & " -r -h -s")
End If

Set oTextStream = objFSO.OpenTextFile(BootIni)
[green]'make an array from the data file[/green]
BootIniTxt = Split(oTextStream.ReadAll, vbNewLine)

[green]'First check if Safe Mode alredy configured and quit if so.[/green]
For Each line In BootIniTxt
	If InStr(1,line,"Safe Mode") Then
		WScript.Echo "Safe Mode Already Configured"
		LockFile
		WScript.Quit
	End If
Next
[green]
'OK, Now find where the Windows install is located and add the safe mode line.[/green]
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
[green]
'Open Boot.ini for writing and write new text[/green]
Set ts = objFSO.OpenTextFile (BootIni, ForWriting)
ts.write Report
ts.close
WScript.Sleep 300
LockFile


Sub LockFile[green]
	'Return file to previous ReadOnly, Hidden, System File state	[/green]
	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
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top