@echo off
CLS
color 1f

REM *** IMPORTANT ***
REM If you wish to use in UserTweaks.cmd or for being called from SetupComplete.cmd remove 
REM the :: from the line with ':: GOTO :CPanelRoutine' failure to do this will cause Windows 
REM Setup to 'hang' as it will be asking for user input but nothing will be shown on the
REM display due to the way Oobe is designed.

:: GOTO :CPanelRoutine

TITLE Checking for Admin...
echo.
cd %systemroot%\system32
call :IsAdmin

TITLE Control Panel Context Menu
cls
color 1f
echo.
REM Enable Unicode
chcp 65001 >nul
echo.
echo Note: This will be hopefully auto translated to your OS language.
echo.

SET /p "CPanelCM=Add Control Panel to the Desktop Context Menu ? {Y/N} "
echo.
IF /I "%CPanelCM%" NEQ "Y" echo Control Panel NOT added. & echo. & GOTO :Done

REM CPCTLocation (default Bottom) is the area on the Context Menu you wish to place the 'link'
REM Top , Middle, Bottom are the only options and may default to Middle or Bottom if spelt wrong.

:CPanelRoutine
SET "CPCTLocation=Top"

REM If you wish to remove the link from the Context Menu copy/paste the REG DELETE line below into a Admin Command Prompt.

REM Remove CPanel Context Menu
Reg delete "HKCR\DesktopBackground\Shell\ControlPanel" /f >nul 2>&1


REM Now add the CPanel to Context Menu...
Reg add "HKCR\DesktopBackground\Shell\ControlPanel" /v "MUIVerb" /t REG_SZ /d "@%SystemRoot%\system32\shell32.dll,-4161" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel" /v "SubCommands" /t REG_SZ /d "" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel" /v "Icon" /t REG_SZ /d "imageres.dll,-27" /f >nul 2>&1
IF /I "%CPCTLocation%" NEQ "Top" IF /I "%CPCTLocation%" NEQ "Middle" IF /I "%CPCTLocation%" NEQ "Bottom" SET "CPCTLocation=Top"
Reg add "HKCR\DesktopBackground\Shell\ControlPanel" /v "Position" /t REG_SZ /d "%CPCTLocation%" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel\shell\001flyout" /ve /t REG_SZ /d "@%SystemRoot%\system32\shell32.dll,-31061" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel\shell\001flyout" /v "Icon" /t REG_SZ /d "imageres.dll,-27" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel\shell\001flyout\command" /ve /t REG_SZ /d "explorer.exe shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel\shell\002flyout" /ve /t REG_SZ /d "@%SystemRoot%\system32\shell32.dll,-32012" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel\shell\002flyout" /v "Icon" /t REG_SZ /d "imageres.dll,-27" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel\shell\002flyout\command" /ve /t REG_SZ /d "explorer.exe shell:::{21EC2020-3AEA-1069-A2DD-08002B30309D}" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel\shell\003flyout" /ve /t REG_SZ /d "@%SystemRoot%\system32\shell32.dll,-32537" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel\shell\003flyout" /v "Icon" /t REG_SZ /d "imageres.dll,-27" /f >nul 2>&1
Reg add "HKCR\DesktopBackground\Shell\ControlPanel\shell\003flyout\command" /ve /t REG_SZ /d "explorer.exe shell:::{ED7BA470-8E54-465E-825C-99712043E01C}" /f >nul 2>&1

echo.
echo Done.

:Done
echo.
echo No reboot or log out is required. Exiting in 5 seconds.
echo.
TIMEOUT /T 5 /NoBreak >nul
GOTO :EOF
=====================================================================================
:IsAdmin
Reg.exe query "HKU\S-1-5-19\Environment"
If Not %ERRORLEVEL% EQU 0 (
 Cls & echo. & Echo You must have administrator rights to continue ... & echo.
 Pause & Exit
)
Cls

exit /b