Manage Speculative Execution Protection Settings

Discussion in 'Windows 10' started by dhjohns, Jan 26, 2018.

  1. dhjohns

    dhjohns MDL Guru

    Sep 5, 2013
    3,262
    1,733
    120
    I modified @Polo6RGTI 's script, and am posting with his permission. It installs needed modules automatically, and without user intervention. Code is slightly cleaned up, and I have his permission to share!
    Code:
    @echo off
    :: Manage Speculative Execution Protection Settings.
    :: Author: Hendrik Vermaak, 23 January 2018
    :: Code Revisions:  D. Johnson 26 January 2018
    :: Setting DOS Windows Title
    title Manage Speculative Execution Protection
    
    COLOR 02
    
    :: Check for administrative permissions
    (cd /d "%~dp0")&&(NET FILE||(powershell start-process -FilePath '%0' -verb runas)&&(exit /B)) >NUL 2>&1
    setlocal ENABLEDELAYEDEXPANSION
    pushd "%~dp0"
    echo.
    echo.
    echo Getting Ready
    echo.
    echo.
    PowerShell Set-ExecutionPolicy -scope currentuser -ExecutionPolicy unrestricted -Force
    PowerShell Set-PSRepository -InstallationPolicy Trusted -Name PSGallery
    PowerShell import-packageprovider nuget -force -RequiredVersion 2.8.5.208 >NUL 2>&1
    PowerShell Install-Module SpeculationControl
    :: Main Script Start
    :menu12
    cls
    echo.
    echo =============== Manage Speculative Execution Protection Settings Menu ===============
    echo.
    echo Please Select one of the listed options:
    echo.
    echo.
    echo [1] Check Speculative Execution Protection Status.
    echo.
    echo [2] Enable Speculative Execution Protection. (PC Performance will be Reduced)
    echo.
    echo [3] Disable Speculative Execution Protection to Increase PC Performance.
    echo.
    echo.
    echo.
    echo [x] Exit.
    echo.
    echo. 
    choice /C 123x /M "Make Your Choice:"
    goto menu%errorlevel%
    :menu1
    cls
    echo.
    echo =============== Speculative Execution Protection Status ==============
    echo.
    PowerShell.exe -Command "Set-ExecutionPolicy RemoteSigned -Scope Currentuser" >NUL 2>&1
    PowerShell.exe -Command "Get-SpeculationControlSettings"
    echo Press any key to continue
    Pause>Nul
    PowerShell.exe -Command "Set-ExecutionPolicy Restricted -Scope Currentuser" >NUL 2>&1
    PowerShell.exe -Command "Get-ExecutionPolicy -List"
    echo Please Press any key to go back to the Main Menu.
    Pause>Nul
    goto menu12
    
    :menu2
    cls
    echo.
    echo Enabling Speculative Execution Protection
    echo.
    timeout /t 1 /nobreak >NUL 2>&1
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverride /t REG_DWORD /d 0 /f >NUL 2>&1
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverrideMask /t REG_DWORD /d 3 /f >NUL 2>&1
    timeout /t 1 /nobreak >NUL 2>&1
    cls
    goto next1
    cls
    :next1
    echo.
    echo ============== Speculative Execution Protection has been Enabled. ===============
    echo.
    echo The computer needs to be Restarted for the Settings to take effect.
    echo.
    echo [1] Restart the computer now? Please ensure any unfinished work is saved before restarting.
    echo.
    echo [2] Go back to the Main menu.
    echo.
    echo.
    echo.
    echo [x] Exit the script without Restarting.
    echo.
    choice /C 12x /M "Make Your Choice:"
    goto menu1%errorlevel%
    :menu3
    cls
    echo.
    echo Disabling Speculative Execution Protection
    echo.
    timeout /t 1 /nobreak >NUL 2>&1
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverride /t REG_DWORD /d 3 /f >NUL 2>&1
    reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverrideMask /t REG_DWORD /d 3 /f >NUL 2>&1
    timeout /t 1 /nobreak >NUL 2>&1
    cls
    goto next2
    cls
    :next2
    echo.
    echo =============== Speculative Execution Protection has been Disabled. ===============
    echo.
    echo The computer needs to be Restarted for the Settings to take effect.
    echo.
    echo [1] Restart the computer now? Please ensure any unfinished work is saved before restarting.
    echo.
    echo [2] Go back to the Main menu.
    echo.
    echo.
    echo.
    echo [x] Exit the script without Restarting.
    echo.
    choice /C 12x /M "Make Your Choice:"
    goto menu1%errorlevel%
    :menu11
    PowerShell restart-computer -Force
    
    :menu13
    goto menu4
    :menu4
    set sec=5
    :continue                                   
    cls
    echo This Program Will Exit in %sec% Seconds
    set /a sec="%sec%-1"
    if %sec%==-1  goto done
    ping -n 2 127.0.0.1 >NUL
    goto continue
    :done
    taskkill >nul 2>&1
    File is also attached for download.
    SHA1: C0095B330464AD377A3BDFC7FF4F1C043F775C29
    MD5: 473E5ED104F577F05F3368FBBE8839B6
    CRC32: 2F522A69
     

    Attached Files:

    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...