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/OperatingSystem.wsf
<package>
    <?component error="true" debug="true" ?>
    <reference object="WbemScripting.SWbemLocator"/>
    <comment>
      Configures the Windows operating system.
    </comment>
    <component id="OperatingSystem">
        <registration
            progid="WaGuest.OperatingSystem"
            description=""
            version="1.0.0.0"
            clsid="{D64AA2FA-1D4A-4318-B150-023DF996D610}"/>

        <public>
            <property name="WScript" />
            <method name="Initialize" />
            <method name="SetPageFile">
              <param name="pageFilePath" />
              <param name="minSizeInMB" />
              <param name="maxSizeInMB" />
            </method>
            <method name="GetPageFileSettings">
              <param name="suppressErrors" />
            </method>
            <method name="GetTempPageFileSettings">
              <param name="suppressErrors" />
            </method>
            <method name="RenameDefaultAdministratorAccount">
              <param name="newUsername" />
            </method>
            <method name="ResetDefaultAdministratorUser">
              <param name="settingsFilePath" />
            </method>
            <method name="ResetTimeZone">
                <param name="newTimeZone" />
            </method>
            <method name="GetRdpCertificateThumbprint" />
            <method name="ConfigureTimeSettings" />
            <method name="ConfigureTimeService" />
            <method name="ConfigureAutomaticUpdates" />
            <method name="ConfigureSanPolicy" />
            <method name="ConfigureSanPolicyOfflined" />
            <method name="ConfigureRdpKeepAlive" />
            <method name="RemoveWinRmListeners" />
            <method name="ConfigureWinRmHttpListener" />
            <method name="ConfigureWinRmHttpsListener" />
            <method name="AddFirewallRule" />
            <method name="ChangeWinRmServiceStartModeAuto" />
            <method name="RestartWinRmService" />
            <method name="CreateScheduledTask">
              <param name="taskName" />
              <param name="taskFile" />
            </method>
            <method name="DeleteScheduledTask">
              <param name="taskName" />
            </method>
        </public>

        <object id="WshShell" progid="WScript.Shell" />

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

        <script language="VBScript">

            Const aunlDisabled = 1
            Const aunlNotifyBeforeInstallation = 3
            Const aunlScheduledInstallation = 4
            Const sanPolicyMountAllStorage = 1
            Const sanPolicyMountAllStorageExceptSharedBus = 2

            Const ERROR_CONFIGURETIMESERVICE = 19

            Dim g_Trace
            Dim oTraceEvent

            Sub Initialize
                Set g_Trace = GetScriptObject(Me.WScript, "Tracing.wsf", "TraceSource")
                g_Trace.Name = "OperatingSystem"
            End Sub

            Sub RenameDefaultAdministratorAccount(newUsername)
                On Error Resume Next

                Dim oResults, oTraceEvent
                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("RenameDefaultAdministratorAccount"))
                    .setAttribute "new", CStr(newUsername)

                    Set oResults = ExecuteAndTraceWithResults("%SystemRoot%\OEM\WaGuest.exe /renameadmin " & QuoteString(newUsername), g_Trace)
                    If oResults.ExitCode <> 0 Then
                        Err.Raise vbObjectError + 12, "OperatingSystem.wsf", "Failed to rename administator account (" & oResults.StdErr & ")"
                    End If
                End With
                g_Trace.TraceEvent oTraceEvent
            End Sub

            Sub ResetDefaultAdministratorUser(settingsFilePath)
                On Error Resume Next

                Dim oResults, oTraceEvent
                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("ResetDefaultAdministratorUser"))

                    Set oResults = ExecuteAndTraceWithResults("%SystemRoot%\OEM\WaGuest.exe /setadminuser " & QuoteString(settingsFilePath), g_Trace)
                    If oResults.ExitCode <> 0 Then
                        Err.Raise vbObjectError + 13, "OperatingSystem.wsf", "Failed to reset administator password (" & oResults.StdErr & ")"
                    End If
                End With
                g_Trace.TraceEvent oTraceEvent
            End Sub

            Sub ResetTimeZone (newTimeZone)
                On Error Resume Next

                Dim oResults, oTraceEvent
                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("ResetTimeZone"))
                    Set oResults = ExecuteAndTraceWithResults("tzutil /s " & Chr(34) & newTimeZone & Chr(34), g_Trace)
                    If oResults.ExitCode <> 0 Then
                        Err.Raise vbObjectError + 21, "OperatingSystem.wsf", "Failed to reset time zone (" & oResults.StdErr & ")"
                    End If
                End With
                g_Trace.TraceEvent oTraceEvent
            End Sub

            ' Creates a scheduled task using the given task file
            ' returns the exitcode of schtasks
            Function CreateScheduledTask(taskName, taskFile)
                On Error Resume Next

                Dim oResults, oTraceEvent, taskCommand

                taskCommand = "%SystemRoot%\System32\schtasks.exe /create /tn " & taskName & " /xml " & taskFile
                Set oResults = ExecuteAndTraceWithResults(taskCommand, g_Trace)

                If oResults.ExitCode = 0 Then
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("CreateScheduledTask"))
                        .setAttribute "task", CStr(taskName)
                    End With
                    g_Trace.TraceEvent oTraceEvent
                End If

                CreateScheduledTask = oResults.ExitCode
            End Function

            ' Delete a scheduled task
            ' returns the exitcode of schtasks
            Function DeleteScheduledTask(taskName)
                On Error Resume Next

                Dim oResults, oTraceEvent, taskCommand

                taskCommand = "%SystemRoot%\System32\schtasks.exe /delete /tn " & taskName & " /f"
                Set oResults = ExecuteAndTraceWithResults(taskCommand, g_Trace)

                If oResults.ExitCode = 0 Then
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("DeleteScheduledTask"))
                        .setAttribute "task", CStr(taskName)
                    End With
                    g_Trace.TraceEvent oTraceEvent
                End If

                DeleteScheduledTask = oResults.ExitCode
            End Function

            ' This function returns whether or not the page file needed to be configured to indicate
            ' whether or not a reboot is required.
            Function SetPageFile(pageFilePath, minSizeInMB, maxSizeInMB)

                SetPageFile = False

                ' check if the page file is already on the specified path.
                ' if it is, then we do not need to set the page file again. Also return False
                ' to indicate to caller that no reboot will be required.
                pageFilePathAndSize = pageFilePath & " " & minSizeInMB & " " & maxSizeInMB

                If PageFileExistsOnPathWithGivenSize(pageFilePathAndSize) = True Then
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("ConfigurePageFile"))
                         .Text = "Page file already exists on the specified path with given size."
                    End With
                    g_Trace.TraceEvent oTraceEvent
                    Exit Function
                End If

                ' note: cannot use StdRegProv because WMI doesn't work in specialize pass, where this logic is likely to run
                regValue = Array(pageFilePath & " " & minSizeInMB & " " & maxSizeInMB)

                SetRegistryValue g_Trace, _
                    "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management", _
                    "PagingFiles", _
                    "REG_MULTI_SZ", _
                    regValue, False

                If Err.Number <> 0 Then
                    Err.Raise vbObjectError + 2, "OperatingSystem.wsf", "Pagefile could not be configured. ErrNo " & CStr(Err.Number)
                    Exit Function
                End If

                SetPageFile = True

                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("PageFileRemediation"))
                    .setAttribute "pageFilePath", pageFilePath
                    .setAttribute "minSizeInMB", minSizeInMB
                    .setAttribute "maxSizeInMB", maxSizeInMB
                End With
                g_Trace.TraceEvent oTraceEvent

            End Function

            Function GetRdpCertificateThumbprint
                Dim objService, colTermSettings, objTermSettings

                ' read the certificate info from Win32_TSGeneralSetting, noting that pktPrivacy is needed
                Set objService = GetObject( _
                    "winmgmts:{authenticationLevel=pktPrivacy}!Root/CIMv2/TerminalServices")

                Set colTermSettings = objService.ExecQuery(_
                    "SELECT SSLCertificateSHA1Hash FROM Win32_TSGeneralSetting")

                ' Return the first certificate in the list
                For each objTermSettings in colTermSettings
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("GetRdpCertificateThumbprint"))
                        .setAttribute "CertThumbprint", objTermSettings.SSLCertificateSHA1Hash
                    End With
                    g_Trace.TraceEvent oTraceEvent
                    Exit For
                Next

                GetRdpCertificateThumbprint = objTermSettings.SSLCertificateSHA1Hash
            End Function

            Sub ConfigureTimeSettings
                Dim oExec

                ' note: cannot use StdRegProv because WMI doesn't work in specialize pass, where this logic is likely to run
                SetRegistryValue g_Trace, _
                    "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", _
                    "RealTimeIsUniversal", _
                    "REG_DWORD", _
                    1, False

                If Err.Number <> 0 Then
                    Err.Raise vbObjectError + 4, "OperatingSystem.wsf", "Time settings could not be configured in the registry (" & Err.Number & ")."
                    Exit Sub
                End If
            End Sub

            Sub ConfigureTimeService
                Dim enableServiceCommand, oResults

                enableServiceCommand = "%SystemRoot%\OEM\WaGuest.exe /configureservicestartmode W32Time Automatic 0"
                Set oResults = ExecuteAndTraceWithResults(enableServiceCommand, g_Trace)
                If oResults.ExitCode <> 0 Then
                    Err.Raise vbObjectError + ERROR_CONFIGURETIMESERVICE, "OperatingSystem.wsf", "Failed to configure W32Time start mode"
                    Exit Sub
                End If

                timeCommand = "cmd /c sc triggerinfo w32time delete"
                ExecuteAndTraceWithResults timeCommand, g_Trace

                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("TimeServiceConfigured"))
                g_Trace.TraceEvent oTraceEvent
            End Sub

            Sub ConfigureAutomaticUpdates(enabled)
                Dim objAutoUpdate, objSettings
                Dim hour, osBuildNumber
                Dim enableCommand, disableCommand

                osBuildNumber = GetOSCurrentBuildNumber
                If (IsEmpty(osBuildNumber) or IsNull(osBuildNumber) or osBuildNumber = "") Then
                    Err.Raise vbObjectError + 10, "OperatingSystem.wsf", "ConfigureAutomaticUpdates: Failed to retrieve current OS build number, cannot configure Windows updates"
                    Exit Sub
                End If

                If CInt(osBuildNumber) >= 10240 Then
                    ' For Win10 VMs configuration is done by registry values, NoAutoUpdate supersedes AUOptions
                    If enabled = True Then
                        disableValue = 0

                        SetRegistryValue g_Trace, _
                            "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU", _
                            "AUOptions", _
                            "REG_DWORD", _
                            aunlScheduledInstallation, False
                    ElseIf enabled = False Then
                        disableValue = 1
                    Else
                        Err.Raise vbObjectError + 11, "OperatingSystem.wsf", "ConfigureAutomaticUpdates: Expected a boolean value for parameter 'enabled', actual value: '" & enabled & "'"
                        Exit Sub
                    End If

                    SetRegistryValue g_Trace, _
                        "HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU", _
                        "NoAutoUpdate", _
                        "REG_DWORD", _
                        disableValue, False
                Else
                    Set objAutoUpdate = CreateObject("Microsoft.Update.AutoUpdate")
                    Set objSettings = objAutoUpdate.Settings

                    If enabled = True Then
                        objSettings.NotificationLevel = aunlScheduledInstallation
                    ElseIf enabled = False Then
                        objSettings.NotificationLevel = aunlDisabled
                    Else
                        Err.Raise vbObjectError + 11, "OperatingSystem.wsf", "ConfigureAutomaticUpdates: Expected a boolean value for parameter 'enabled', actual value: '" & enabled & "'"
                        Exit Sub
                    End If

                    objSettings.Save
                End If

                If enabled = True Then
                    'Choose a random hour between 0100 and 0500 hrs to install Windows Updates
                    'Randomize the windows update install time for load distribution.
                    Randomize()
                    hour = CInt(Int((5 * Rnd()) + 1))

                    If CInt(osBuildNumber) < 8100 Then
                        'For Windows Server 2008 R2 and earlier VMs
                        objSettings.ScheduledInstallationTime = hour
                        objSettings.Save
                    Else
                        'For Windows Server 2012 and later VMs
                        timeString = "2013-01-01T0" & CStr(hour) & ":00:00"
                        cmdLine = "%SystemRoot%\OEM\WaGuest.exe /setwin8updateinstalltime """ & timeString & """"
                        ExecuteAndTraceWithResults cmdLine, g_Trace
                    End If
                End If

                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("ConfigureAutomaticUpdates"))
                    .setAttribute "enabled", enabled
                    .setAttribute "scheduledInstallationTime", hour
                End With
                g_Trace.TraceEvent oTraceEvent
            End Sub

            ' This function returns whether or not the san policy needed to be configured.
            ' If it configured SAN policy, reboot is required.
            Function ConfigureSanPolicy

                Dim oResults, currentSanPolicy

                ConfigureSanPolicy = False

                currentSanPolicy = GetCurrentSanPolicy()
                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("ConfigureSanPolicy"))
                    .setAttribute "CurrentSanPolicy", currentSanPolicy
                End With
                g_Trace.TraceEvent oTraceEvent

                If currentSanPolicy = sanPolicyMountAllStorage Then
                    ' SanPolicy is already set to 1 (OnlineAll).
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("ConfigureSanPolicy"))
                        .Text = "SanPolicy is already set to 1 (OnlineAll). Not setting again."
                    End With
                    g_Trace.TraceEvent oTraceEvent
                    Exit Function
                End If

                Set oResults = ExecuteAndTraceWithResults("DISKPART /s %SystemRoot%\OEM\SetSanPolicy.txt", g_Trace)

                If oResults.ExitCode = 0 Then
                    ' san policy set

                    ConfigureSanPolicy = True
                    Set oTraceEvent = g_Trace.CreateEvent("INFO")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("ConfigureSanPolicy"))
                        .setAttribute "policy", "OnlineAll"
                    End With
                    g_Trace.TraceEvent oTraceEvent
                Else
                    ' unknown failure
                    Err.Raise vbObjectError + 5, "OperatingSystem.wsf", "Failed to set the SAN policy (" & oResults.StdErr & ")"
                End If
            End Function

            Function ConfigureSanPolicyOfflined
                ' Default to False in order to avoid an unnecessary reboot.
                ' True indicates that we set SanPolicy. We didn't.
                ConfigureSanPolicyOfflined = False
            End Function

            ' keepAliveEnable value is a boolean (True|False)
            ' keepAliveInterval value is in minutes (int)
            Sub ConfigureRdpKeepAlive(keepAliveEnable, keepAliveInterval)
                On Error Resume Next

                Dim terminalServicesKey, keepAliveEnableKey, keepAliveIntervalKey

                terminalServicesKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services"
                keepAliveEnableKey = terminalServicesKey & "\KeepAliveEnable"
                keepAliveIntervalKey = terminalServicesKey & "\KeepAliveInterval"

                keepAliveEnable = Abs(CInt(keepAliveEnable))

                WshShell.RegWrite keepAliveEnableKey, keepAliveEnable, "REG_DWORD"
                If TraceError(g_Trace, "ConfigureRdpKeepAlive: Setting registry key " & keepAliveEnableKey & " = " & keepAliveEnable & " failed") <> 0 Then
                    Err.Raise vbObjectError + 6, "OperatingSystem.wsf", "Failed to set RDP keep-alive key: " & keepAliveEnableKey
                    Exit Sub
                End If

                WshShell.RegWrite keepAliveIntervalKey, keepAliveInterval, "REG_DWORD"
                If TraceError(g_Trace, "ConfigureRdpKeepAlive: Setting registry key " & keepAliveIntervalKey & " = " & keepAliveInterval & " failed") <> 0 Then
                    Err.Raise vbObjectError + 6, "OperatingSystem.wsf", "Failed to set RDP keep-alive key: " & keepAliveIntervalKey
                    Exit Sub
                End If

                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("ConfigureRdpKeepAlive"))
                    .setAttribute "KeepAliveEnable", CStr(keepAliveEnable)
                    .setAttribute "KeepAliveInterval", CStr(keepAliveInterval)
                End With
                g_Trace.TraceEvent oTraceEvent
            End Sub

            Sub AddFirewallRule (name, program, protocol, port, remoteaddresses, removeExisting)
                On Error Resume Next
                Dim oTraceEvent, policy, fwMgr, fwRule, errornum

                Set fwMgr = CreateObject("HNetCfg.FwMgr")
                Set oTraceEvent = g_Trace.CreateEvent("INFO")

                With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("AddFirewallRule"))
                    .setAttribute "name", CStr(name)
                    .setAttribute "protocol", CStr(protocol)
                    .setAttribute "port", CStr(port)
                    .setAttribute "remoteaddresses", CStr(remoteaddresses)

                    g_Trace.TraceEvent oTraceEvent

                    Set policy = CreateObject("HNetCfg.FwPolicy2")

                    If removeExisting = True Then policy.Rules.Remove name

                    Set fwRule = CreateObject("HNetCfg.FwRule")
                    fwRule.Name = name
                    fwRule.ApplicationName = program
                    fwRule.RemoteAddresses = remoteaddresses
                    fwRule.Protocol = protocol
                    fwRule.LocalPorts = port
                    fwRule.Grouping = "@firewallapi.dll,-23255" 'None
                    fwRule.Enabled = True

                    policy.Rules.Add fwRule

                    errornum = Err.Number
                    If errornum <> 0 Then
                        Err.Raise vbObjectError + 8, "OperatingSystem.wsf", "Failed to add firewall rule."
                    End If
                End With
            End Sub

            Sub RemoveWinRmListeners
                On Error Resume Next

                Dim strKeyPath : strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Listener\*+HTTP"
                DeleteRegistry g_Trace, strKeyPath, "", True
                strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Listener\*+HTTPS"
                DeleteRegistry g_Trace, strKeyPath, "", True
            End Sub

            Sub ConfigureWinRmHttpsListener(port, certificateThumbprint)
                On Error Resume Next
                Const strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Listener"
                Const selector = "*+HTTPS"
                Const uriprefix = "wsman"

                Dim oResults, element, oTraceEvent, httpsListenerKeyPath

                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                Set element = oTraceEvent.ownerDocument.createElement("ConfigureWinRmHttpsListener")

                element.setAttribute "uriprefix", uriprefix
                element.setAttribute "port", port
                element.setAttribute "CertificateThumbprint", certificateThumbprint
                oTraceEvent.AppendChild(element)

                httpsListenerKeyPath = strKeyPath & "\" & selector
                SetRegistryValue g_Trace, httpsListenerKeyPath, "uriprefix", "REG_SZ", uriprefix, False
                If Err.Number <> 0 Then
                    Err.Raise vbObjectError + 14, "OperatingSystem.wsf", "Failed to set uriprefix for WinRM https listener"
                    Exit Sub
                End If

                SetRegistryValue g_Trace, httpsListenerKeyPath, "Port", "REG_DWORD", port, False
                If Err.Number <> 0 Then
                    Err.Raise vbObjectError + 15, "OperatingSystem.wsf", "Failed to set port for WinRM https listener"
                    Exit Sub
                End If

                SetRegistryValue g_Trace, httpsListenerKeyPath, "certThumbprint", "REG_SZ", certificateThumbprint, False
                If Err.Number <> 0 Then
                    Err.Raise vbObjectError + 16, "OperatingSystem.wsf", "Failed to set certThumbprint for WinRM https listener"
                    Exit Sub
                End If

                Set oResults = ExecuteAndTraceWithResults ("%SystemRoot%\OEM\WaGuest.exe /sethttpsslconfiguration " & port & " " & QuoteString(certificateThumbprint), g_Trace)

                oTraceEvent.appendChild(element)
                g_Trace.TraceEvent oTraceEvent

                If oResults.ExitCode <> 0 Then
                    Err.Raise vbObjectError + 7, "OperatingSystem.wsf", "Failed to configure Http.sys for WinRM"
                    Exit Sub
                End If
            End Sub

            Sub ConfigureWinRmHttpListener(port)
                On Error Resume Next
                Const strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Listener"
                Const selector = "*+HTTP"
                Const uriprefix = "wsman"

                Dim oResults, element, oTraceEvent, httpListenerKeyPath

                Set oTraceEvent = g_Trace.CreateEvent("INFO")
                Set element = oTraceEvent.ownerDocument.createElement("ConfigureWinRmHttpListener")

                element.setAttribute "uriprefix", uriprefix
                element.setAttribute "port", port
                oTraceEvent.AppendChild(element)

                httpListenerKeyPath = strKeyPath & "\" & selector
                SetRegistryValue g_Trace, httpListenerKeyPath, "uriprefix", "REG_SZ", uriprefix, False
                If Err.Number <> 0 Then
                    Err.Raise vbObjectError + 17, "OperatingSystem.wsf", "Failed to set uriprefix for WinRM http listener"
                    Exit Sub
                End If

                SetRegistryValue g_Trace, httpListenerKeyPath, "Port", "REG_DWORD", port, False
                If Err.Number <> 0 Then
                    Err.Raise vbObjectError + 18, "OperatingSystem.wsf", "Failed to set port for WinRM http listener"
                    Exit Sub
                End If

                element.setAttribute "result", "ConfigureWinRmHttpListener provisioned WinRM HTTP listener successfully."
                oTraceEvent.appendChild(element)
                g_Trace.TraceEvent oTraceEvent
            End Sub

            Sub ChangeWinRmServiceStartModeAuto
                On Error Resume Next
                Dim oResults, oTraceEvent, element
                Set oResults = ExecuteAndTraceWithResults("sc config winrm start= auto", g_Trace)

                If oResults.ExitCode <> 0 Then
                    Err.Raise vbObjectError + 9, "OperatingSystem.wsf", "Failed to set the WinRM service to auto-start. ERRORLEVEL=" & oResults.ExitCode
                    Exit Sub
                End If
            End Sub

            Sub RestartWinRmService(WScript)
                On Error Resume Next
                Dim strCommand : strCommand = "%SYSTEMROOT%\OEM\WaGuest.exe /restartservice " & QuoteString("WinRM")
                Dim oResults : Set oResults = ExecuteAndTraceWithResults(strCommand, g_Trace)

                If oResults.ExitCode <> 0 Then
                    Err.Raise vbObjectError + 20, "OperatingSystem.wsf", "Failed to restart the WinRM service"
                    Exit Sub
                End If
            End Sub

            ' This function returns the current SAN policy set in registry.
            Private Function GetCurrentSanPolicy
                const fullPath = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\partmgr\Parameters"

                Dim registryValue

                GetCurrentSanPolicy = sanPolicyMountAllStorageExceptSharedBus

                registryValue = GetRegistryValue(g_Trace, fullPath, "SanPolicy", "REG_DWORD", False)

                If IsNull(registryValue) Then
                    Set oTraceEvent = g_Trace.CreateEvent("ERROR")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("GetCurrentSanPolicy"))
                        .Text = "Failed to find a value for SanPolicy in registry."
                    End With
                    g_Trace.TraceEvent oTraceEvent
                    Exit Function
                End If
                GetCurrentSanPolicy = registryValue
            End Function

            ' This function returns true if the page file set in the registry matches the
            ' value of the page file that was passed as argument; false otherwise.
            Private Function PageFileExistsOnPathWithGivenSize(pageFilePathAndSize)

                Dim registryValue

                PageFileExistsOnPathWithGivenSize = False

                registryValue = GetPageFileSettings(False)

                If IsNull(registryValue) Then
                    Set oTraceEvent = g_Trace.CreateEvent("ERROR")
                    With oTraceEvent.appendChild(oTraceEvent.ownerDocument.createElement("PageFileExistsOnPathWithGivenSize"))
                        .Text = "Failed to find value for PagingFiles in registry."
                    End With
                    g_Trace.TraceEvent oTraceEvent
                    Exit Function
                End If

                For Each value In registryValue
                    If LCase(value) = LCase(pageFilePathAndSize) Then
                        PageFileExistsOnPathWithGivenSize = True
                        Exit Function
                    End If
                Next
            End Function

            Function GetPageFileSettings(suppressErrors)
                Const KeyPath = "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
                Const Value = "PagingFiles"
                GetPageFileSettings = GetRegistryValue(g_Trace, KeyPath, Value, "REG_MULTI_SZ", suppressErrors)
            End Function

            Function GetTempPageFileSettings(suppressErrors)
                Const KeyPath = "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
                Const Value = "TempPageFile"
                GetTempPageFileSettings = GetRegistryValue(g_Trace, KeyPath, Value, "REG_DWORD", suppressErrors)
            End Function
        </script>
    </component>
</package>