﻿@echo off
setlocal EnableExtensions EnableDelayedExpansion
title Disable Windows Setup Prompts - All Users

:: ================================================================
:: Disable Windows "Finish setting up your PC/device" prompts
:: Windows 10 / Windows 11
::
:: Applies to:
::   - All existing local/domain user profiles found on this PC
::   - Users whose registry hives are currently loaded
::   - Users who are currently signed out
::   - The Default User profile, so NEW users inherit the settings
::
:: This script self-elevates to Administrator.
:: ================================================================

:: ---- Self-elevate if not running as Administrator ----------------
fltmc >nul 2>&1
if errorlevel 1 (
    echo Requesting Administrator privileges...
    powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
      "Start-Process -FilePath '%~f0' -Verb RunAs"
    exit /b
)

echo.
echo ================================================================
echo  Disable Windows Setup / Welcome / Tips Prompts - ALL USERS
echo ================================================================
echo.

set "ERRORS=0"
set /a COUNT=0

:: ---- Machine-wide policy: disable Windows soft-landing/tips -------
echo [1/3] Applying machine-wide policy...
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\CloudContent" ^
    /v "DisableSoftLanding" /t REG_DWORD /d 1 /f >nul 2>&1
if errorlevel 1 (
    echo       WARNING: Could not set machine-wide DisableSoftLanding policy.
    set /a ERRORS+=1
) else (
    echo       OK
)

:: ---- Apply to every existing Windows profile ---------------------
echo.
echo [2/3] Applying settings to existing user profiles...

for /f "delims=" %%K in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" 2^>nul ^| findstr /R /C:"S-1-5-21-"') do (
    set "SID="
    set "PROFILEPATH="

    for %%S in ("%%K") do set "SID=%%~nxS"

    for /f "tokens=2,*" %%A in ('reg query "%%K" /v "ProfileImagePath" 2^>nul ^| findstr /I "ProfileImagePath"') do (
        set "PROFILEPATH=%%B"
    )

    if defined SID if defined PROFILEPATH (
        call :ProcessProfile "!SID!" "!PROFILEPATH!"
    )
)

:: ---- Apply to Default User so future users inherit it ------------
echo.
echo [3/3] Applying settings to the Default User profile...

set "DEFAULTDAT=%SystemDrive%\Users\Default\NTUSER.DAT"

if exist "%DEFAULTDAT%" (
    reg unload "HKU\AAI_DefaultUser_Temp" >nul 2>&1
    reg load "HKU\AAI_DefaultUser_Temp" "%DEFAULTDAT%" >nul 2>&1

    if errorlevel 1 (
        echo       WARNING: Could not load Default User registry hive.
        set /a ERRORS+=1
    ) else (
        call :ApplySettings "HKU\AAI_DefaultUser_Temp"
        reg unload "HKU\AAI_DefaultUser_Temp" >nul 2>&1
        echo       OK - New Windows users will inherit these settings.
    )
) else (
    echo       WARNING: Default User NTUSER.DAT was not found.
    set /a ERRORS+=1
)

echo.
echo ================================================================
echo  COMPLETE
echo ================================================================
echo  Existing profiles processed : %COUNT%
echo  Warnings/errors             : %ERRORS%
echo.
echo  Disabled:
echo    - "Let's finish setting up your device / PC"
echo    - "Get even more out of Windows"
echo    - Windows welcome experience after updates/sign-in
echo    - Windows tips and suggestions
echo    - Windows soft-landing tips
echo.
echo  Restart Windows, or sign users out and back in, for all
echo  settings to take effect.
echo ================================================================
echo.
pause
exit /b


:: =================================================================
:: Process one user profile.
:: If the user's HKU hive is loaded, edit it directly.
:: Otherwise temporarily load that user's NTUSER.DAT.
:: =================================================================
:ProcessProfile
set "P_SID=%~1"
set "P_PATH=%~2"
set /a COUNT+=1

echo       User: %P_PATH%

reg query "HKU\%P_SID%" >nul 2>&1
if not errorlevel 1 (
    call :ApplySettings "HKU\%P_SID%"
    echo             OK - loaded profile
    exit /b
)

set "P_NTUSER=%P_PATH%\NTUSER.DAT"
if not exist "%P_NTUSER%" (
    echo             SKIPPED - NTUSER.DAT not found
    set /a ERRORS+=1
    exit /b
)

set "TEMPHIVE=AAI_User_%COUNT%"
reg unload "HKU\%TEMPHIVE%" >nul 2>&1
reg load "HKU\%TEMPHIVE%" "%P_NTUSER%" >nul 2>&1

if errorlevel 1 (
    echo             WARNING - could not load user registry hive
    set /a ERRORS+=1
    exit /b
)

call :ApplySettings "HKU\%TEMPHIVE%"
reg unload "HKU\%TEMPHIVE%" >nul 2>&1
echo             OK - offline profile
exit /b


:: =================================================================
:: Registry settings applied to a user's hive.
:: =================================================================
:ApplySettings
set "HIVE=%~1"

:: Disable "Suggest ways to get the most out of Windows and finish
:: setting up this device" / SCOOBE.
reg add "%HIVE%\Software\Microsoft\Windows\CurrentVersion\UserProfileEngagement" ^
    /v "ScoobeSystemSettingEnabled" /t REG_DWORD /d 0 /f >nul 2>&1

:: Disable Windows welcome experience after updates and sign-in.
reg add "%HIVE%\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" ^
    /v "SubscribedContent-310093Enabled" /t REG_DWORD /d 0 /f >nul 2>&1

:: Disable Windows tips and suggestions.
reg add "%HIVE%\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" ^
    /v "SubscribedContent-338389Enabled" /t REG_DWORD /d 0 /f >nul 2>&1

:: Disable additional Windows soft-landing/tips prompts.
reg add "%HIVE%\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" ^
    /v "SoftLandingEnabled" /t REG_DWORD /d 0 /f >nul 2>&1

exit /b
