- ' bootini.vbs -- modify the boot.ini, locate the DEP option, if set to OptOut
- ' change to AlwaysOff
- Const ForReading = 1
- Const ForWriting = 2
- Const conFileName = "boot.ini"
- Const strFindText = "/NoExecute=OptOut"
- Const strChangeText = "/NoExecute=AlwaysOff"
- Dim strFileName
- On Error Resume Next
- ' retrieve system drive variable from environment...
- Set objShell = CreateObject("WScript.Shell")
- strSystemDrive = objShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
- ' WScript.Echo strSystemDrive
- ' build file name...
- strFileName = strSystemDrive & "\" & conFileName
- ' open the boot.ini file...
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- ' Set objFile = objFSO.OpenTextFile(conFileName, ForReading)
- Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
- strNewText = ""
- strText = objFile.ReadAll
- objFile.Close
- intPos = InStr(1, strText, strFindText)
- If intPos > 0 Then
- ' we have a match... make the change
- strNewText = Replace(strText, strFindText, strChangeText)
- ' turn read only bit off
- x = ToggleArchiveBit ( strFileName )
- ' open boot.ini file for update
- Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
- objFile.WriteLine strNewText
- objFile.Close
- ' turn read only bit on
- x = ToggleArchiveBit ( strFileName )
- End If
- Function ToggleArchiveBit(filespec)
- Dim fso, f
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set f = fso.GetFile(filespec)
- If f.attributes and 1 Then
- f.attributes = f.attributes - 1
- ToggleArchiveBit = "Read bit is cleared."
- Else
- f.attributes = f.attributes + 1
- ToggleArchiveBit = "Read bit is set."
- End If
- End Function