HEX
Server: Apache
System: Windows NT MAGNETO-ARM 10.0 build 22000 (Windows 10) AMD64
User: Michel (0)
PHP: 7.4.7
Disabled: NONE
Upload Files
File: C:/Windows/OEM/BootConfig.wsf
<package>
    <?component error="true" debug="true" ?>
    <comment>
      Configures the Boot Configuration Database.
    </comment>
    <component id="BootConfig">
        <registration
            progid="WaGuest.BootConfig"
            description=""
            version="1.0.0.0"
            clsid="{5655C369-44B8-48DC-81D3-7401366D9FBE}"/>
      
        <public>
            <property name="WScript" />
            <method name="Initialize" />
            <method name="ConfigureBootStatusPolicy" />
            <method name="ConfigureBCD" />
            <method name="ConfigureRecoveryEnabledFlag" />
        </public>
      
        <object id="WshShell" progid="WScript.Shell" />
        <object id="FSO" progid="Scripting.FileSystemObject" />

        <script language="VBScript" src="Utility.vbs" />

        <script language="VBScript">

            Const ERROR_SETBOOTSTATUSPOLICYFAILURE =  1
            Const ERROR_SETDISKIDFAILURE =  2
            Const ERROR_SETBOOTDEVICEFAILURE =  3
            Const ERROR_SETBOOTOSDEVICEFAILURE =  4
            Const ERROR_RECOVERYENABLEMENTFAILURE =  5

            Dim g_Trace
            Dim oTraceEvent
        
            Sub Initialize
                Set g_Trace = GetScriptObject(Me.WScript, "Tracing.wsf", "TraceSource")
                g_Trace.Name = "BootConfig"
            End Sub
			
            Function ConfigureBootStatusPolicy

                Dim oResults
                Set oResults = ExecuteAndTraceWithResults("bcdedit /set {current} bootstatuspolicy ignoreallfailures", g_Trace)

                If oResults.ExitCode = 0 Then
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("BootConfigRemediation"))
                        .appendChild(oTraceEvent.ownerDocument.createElement("BootStatusPolicyUpdated"))
                    End With
                    g_Trace.TraceEvent oTraceEvent
                Else
                    ' unknown failure
                    Err.Raise vbObjectError + ERROR_SETBOOTSTATUSPOLICYFAILURE, "BootConfig.wsf", "Failed to set the bootstatus policy (" & oResults.StdErr & ")" 
                End If

            End Function

            Sub ConfigureBCD
                Const strComputer = "."

                Dim objWMIService, colItems, oTraceEvent
                Set oTraceEvent = g_Trace.CreateEvent("INFO")

                ' Check if there is only one disk which is both the system and the boot partition
                ' and *only* then change BCD entries.
                Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
                Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Volume WHERE BootVolume=true AND SystemVolume=true")

                With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("ConfigureBCD"))
                    .setAttribute "BootAndSystemVolumes", colItems.Count
                End With
                g_Trace.TraceEvent oTraceEvent

                If colItems.Count = 1 Then
                    ChangeCurrentBcdDeviceToBootPartition
					AssignDiskId
                End If
            End Sub

            'Changes the 'device' and 'osdevice' entries in the current operating system's BCD entry to the system partition.
            'IMPORTANT: This subroutine should only be used when the system and boot partition are the same.
            'Also, this should not be used with multi-boot configurations without modification.
            Sub ChangeCurrentBcdDeviceToBootPartition
                Const Current = "{fa926493-6f1c-4193-a414-58f0b2456d1e}"
                Dim bcdEditCommand

                bcdEditCommand = "bcdedit /set " & Current & " device boot"

                Set oExec = ExecuteAndTraceWithResults(bcdEditCommand, g_Trace)

                If oExec.ExitCode = 0 Then
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("BootDeviceConfiguration"))
                        .appendChild(oTraceEvent.ownerDocument.createElement("BootDeviceConfigured"))
                    End With
                    g_Trace.TraceEvent oTraceEvent
                Else
                    ' unknown failure
                    Err.Raise vbObjectError + ERROR_SETBOOTDEVICEFAILURE, "BootConfig.wsf", "Failed to configure boot device (" & oResults.StdErr & ")" 
                End If

                bcdEditCommand = "bcdedit /set " & Current & " osdevice boot"

                Set oExec = ExecuteAndTraceWithResults(bcdEditCommand, g_Trace)

                If oExec.ExitCode = 0 Then
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("BootOsDeviceConfiguration"))
                        .appendChild(oTraceEvent.ownerDocument.createElement("BootOsDeviceConfigured"))
                    End With
                    g_Trace.TraceEvent oTraceEvent
                Else
                    ' unknown failure
                    Err.Raise vbObjectError + ERROR_SETBOOTOSDEVICEFAILURE, "BootConfig.wsf", "Failed to configure boot osdevice (" & oResults.StdErr & ")" 
                End If
            End Sub

            Sub ConfigureRecoveryEnabledFlag
                On Error Resume Next

                Const Current = "{fa926493-6f1c-4193-a414-58f0b2456d1e}"
                Dim bcdEditCommand

                bcdEditCommand = "bcdedit /set " & Current & " recoveryenabled no"

                Set oExec = ExecuteAndTraceWithResults(bcdEditCommand, g_Trace)

                If oExec.ExitCode = 0 Then
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("BootConfigRemediation"))
                        .appendChild(oTraceEvent.ownerDocument.createElement("RecoveryEnabledFlagConfigured"))
                    End With
                    g_Trace.TraceEvent oTraceEvent
                Else
                    ' unknown failure
                    Err.Raise vbObjectError + ERROR_RECOVERYENABLEMENTFAILURE, "BootConfig.wsf", "Failed to configure recoveryenabled flag (" & oResults.StdErr & ")" 
                End If
            End Sub
			
			Sub AssignDiskId
				Dim randomNum, diskId, paddedDiskId, oResults, diskNum, setDiskIdCommand
				Const maxRand =  2147483647 ' 2^31 - 1
				Const minRand = -2147483648 ' -2^31
				
				' generate a random 8-character hex string, maintaining proper sign-extension
				Randomize
				randomNum = Int((maxRand-minRand+1)*Rnd + minRand)
				diskId = Hex(randomNum)
				If randomNum < 0 Then
					paddedDiskId = LeftPad( diskId, 8, "0" )
				Else
					paddedDiskId = LeftPad( diskId, 8, "F" )
				End If
				
                diskNum = 0
                setDiskIdCommand = "%SystemRoot%\OEM\SetDiskId.exe /disknumber " & diskNum & " /diskid " & paddedDiskId
				
				' execute script and report its result
				Set oResults = ExecuteAndTraceWithResults(setDiskIdCommand, g_Trace)
				
				If oResults.ExitCode = 0 Then
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("DiskIdAssignment"))
                        .setAttribute "DiskId", paddedDiskId
                    End With
                    g_Trace.TraceEvent oTraceEvent
                Else
                    ' unknown failure
                    Err.Raise vbObjectError + ERROR_SETDISKIDFAILURE, "BootConfig.wsf", "Failed to set the disk id (" & oResults.StdErr & ")" 
                End If
			End Sub
        </script>
    </component>
</package>