@echo off

REM ############################################################
REM # @description:                                            #
REM #   Copy and set the background and lockscreen             #
REM #   Then prevent them from channging (even from firefox)   #  
REM #   					                                   #
REM #                                                          #
REM # @author: Bram Prieshof                                   #
REM ############################################################

set ImgName=BG.jpg
set NewBG=C:\Windows\Web\Wallpaper\%ImgName%
REM Admin Check
NET SESSION >nul 2>&1
IF %ERRORLEVEL% EQU 0 (
    ECHO Setting background...
) ELSE (
    ECHO Please run this script as administrator
    PAUSE
    EXIT
)

REM Copy background to system
copy "%~dp0%ImgName%" "%NewBG%" >nul 2>&1

REM Disable Lockscreenn personalization
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Personalization >nul 2>&1
IF %ERRORLEVEL% EQU 1 (
    reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Personalization >nul 2>&1
)
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Personalization /v LockScreenImage /t REG_SZ /d "%NewBG%" /f >nul 2>&1
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Personalization /v NoChangingLockScreen /t REG_DWORD /d 1 /f >nul 2>&1

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP >nul 2>&1
IF %ERRORLEVEL% EQU 1 (
    reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP >nul 2>&1
)
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP /V "LockScreenImageStatus" /T REG_DWORD /D "00000001" /F >nul 2>&1
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP /V "LockScreenImagePath" /T REG_SZ /D  "%NewBG%" /F >nul 2>&1
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP /V "LockScreenImageUrl" /T REG_SZ /D  "%NewBG%" /F >nul 2>&1

REM Disable Background personalization
reg query  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System >nul 2>&1
IF %ERRORLEVEL% EQU 1 (
    reg add  HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System >nul 2>&1
)
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System /v WallpaperStyle /t REG_SZ /d 4 /f >nul 2>&1
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System /v Wallpaper /t REG_SZ /d "%NewBG%" /f >nul 2>&1


REM Disable Firefox background set
reg query HKEY_LOCAL_MACHINE\Software\Policies\Mozilla\Firefox >nul 2>&1
IF %ERRORLEVEL% EQU 1 (
    reg add HKEY_LOCAL_MACHINE\Software\Policies\Mozilla\Firefox >nul 2>&1
)
reg add HKEY_LOCAL_MACHINE\Software\Policies\Mozilla\Firefox /v DisableSetDesktopBackground /t REG_DWORD /d 1 /f >nul 2>&1

ECHO Done, Please reboot to apply
PAUSE