@echo off
CLS
color 1f
TITLE Checking for Admin...
echo.
cd %systemroot%\system32
call :IsAdmin

TITLE TakeOwnership Context Menu
cls
color 1f
echo.
REM Enable Unicode
chcp 65001 >nul

REM Variable Admin = Administrators Group, you could have the username, or Administrators spelt in your language. 
REM However *S-1-5-32-544 is language independent for 'Administators'. Leave as it is unless you require a specific name.

SET "Admin=*S-1-5-32-544"

REM Change the CTMenuName variable's 'Take Ownership' wording to your native language. Such as...

REM Dutch -----------> SET "CTMenuName=Neem Eigendom Over"
REM French ----------> SET "CTMenuName=Prendre possession"
REM German ----------> SET "CTMenuName=In Besitz nehmen"
REM Spanish ---------> SET "CTMenuName=Tomar posesión"
REM Portuguese ------> SET "CTMenuName=Tomar posse"

SET "CTMenuName=Take Ownership"

REM Take Ownership Context Menu
Reg delete "HKCR\*\shell\runas" /f >NUL 2>&1
Reg add "HKCR\*\shell\runas" /ve /t REG_SZ /d "%CTMenuName%" /f >NUL 2>&1
Reg add "HKCR\*\shell\runas" /v "HasLUAShield" /t REG_SZ /d "" /f >NUL 2>&1
Reg add "HKCR\*\shell\runas" /v "NoWorkingDirectory" /t REG_SZ /d "" /f >NUL 2>&1
Reg add "HKCR\*\shell\runas" /v "Position" /t REG_SZ /d "middle" /f >NUL 2>&1
Reg add "HKCR\*\shell\runas\command" /ve /t REG_SZ /d "cmd.exe /c takeown /f \"%%1\" && icacls \"%%1\" /grant %Admin%:F /c /l" /f >NUL 2>&1
Reg add "HKCR\*\shell\runas\command" /v "IsolatedCommand" /t REG_SZ /d "cmd.exe /c takeown /f \"%%1\" && icacls \"%%1\" /grant %Admin%:F /c /l" /f >NUL 2>&1

Reg delete "HKCR\Directory\shell\runas" /f >NUL 2>&1
Reg add "HKCR\Directory\shell\runas" /ve /t REG_SZ /d "%CTMenuName%" /f >NUL 2>&1
Reg add "HKCR\Directory\shell\runas" /v "AppliesTo" /t REG_SZ /d "NOT (System.ItemPathDisplay:=\"C:\Users\" OR System.ItemPathDisplay:=\"C:\ProgramData\" OR System.ItemPathDisplay:=\"C:\Windows\" OR System.ItemPathDisplay:=\"C:\Windows\System32\" OR System.ItemPathDisplay:=\"C:\Program Files\" OR System.ItemPathDisplay:=\"C:\Program Files (x86)\")" /f >NUL 2>&1
Reg add "HKCR\Directory\shell\runas" /v "HasLUAShield" /t REG_SZ /d "" /f >NUL 2>&1
Reg add "HKCR\Directory\shell\runas" /v "NoWorkingDirectory" /t REG_SZ /d "" /f >NUL 2>&1
Reg add "HKCR\Directory\shell\runas" /v "Position" /t REG_SZ /d "middle" /f >NUL 2>&1
Reg add "HKCR\Directory\shell\runas\command" /ve /t REG_SZ /d "cmd.exe /c takeown /f \"%%1\" /r /d o && icacls \"%%1\" /grant %Admin%:F /t /c /l /q" /f >NUL 2>&1
Reg add "HKCR\Directory\shell\runas\command" /v "IsolatedCommand" /t REG_SZ /d "cmd.exe /c takeown /f \"%%1\" /r /d o && icacls \"%%1\" /grant %Admin%:F /t /c /l /q" /f >NUL 2>&1

Reg delete "HKCR\dllfile\shell\runas" /f >NUL 2>&1
Reg add "HKCR\dllfile\shell\runas" /ve /t REG_SZ /d "%CTMenuName%" /f >NUL 2>&1
Reg add "HKCR\dllfile\shell\runas" /v "HasLUAShield" /t REG_SZ /d "" /f >NUL 2>&1
Reg add "HKCR\dllfile\shell\runas" /v "NoWorkingDirectory" /t REG_SZ /d "" /f >NUL 2>&1
Reg add "HKCR\dllfile\shell\runas" /v "Position" /t REG_SZ /d "middle" /f >NUL 2>&1
Reg add "HKCR\dllfile\shell\runas\command" /ve /t REG_SZ /d "cmd.exe /c takeown /f \"%%1\" && icacls \"%%1\" /grant %Admin%:F /c /l" /f >NUL 2>&1
Reg add "HKCR\dllfile\shell\runas\command" /v "IsolatedCommand" /t REG_SZ /d "cmd.exe /c takeown /f \"%%1\" && icacls \"%%1\" /grant %Admin%:F /c /l" /f >NUL 2>&1

Reg delete "HKCR\Drive\shell\runas" /f >NUL 2>&1
Reg add "HKCR\Drive\shell\runas" /ve /t REG_SZ /d "%CTMenuName%" /f >NUL 2>&1
Reg add "HKCR\Drive\shell\runas" /v "AppliesTo" /t REG_SZ /d "NOT C:" /f >NUL 2>&1
Reg add "HKCR\Drive\shell\runas" /v "HasLUAShield" /t REG_SZ /d "" /f >NUL 2>&1
Reg add "HKCR\Drive\shell\runas" /v "NoWorkingDirectory" /t REG_SZ /d "" /f >NUL 2>&1
Reg add "HKCR\Drive\shell\runas" /v "Position" /t REG_SZ /d "middle" /f >NUL 2>&1
Reg add "HKCR\Drive\shell\runas\command" /ve /t REG_SZ /d "cmd.exe /c takeown /f \"%%1\" /r /d o && icacls \"%%1\" /grant %Admin%:F /t /c /l /q" /f >NUL 2>&1
Reg add "HKCR\Drive\shell\runas\command" /v "IsolatedCommand" /t REG_SZ /d "cmd.exe /c takeown /f \"%%1\" /r /d o && icacls \"%%1\" /grant %Admin%:F /t /c /l /q" /f >NUL 2>&1

Reg delete "HKCR\exefile\shell\runas" /f >NUL 2>&1
Reg add "HKCR\exefile\shell\runas" /v "HasLUAShield" /t REG_SZ /d "" /f >NUL 2>&1
Reg add "HKCR\exefile\shell\runas\command" /ve /t REG_SZ /d "\"%%1\" %%*" /f >NUL 2>&1
Reg add "HKCR\exefile\shell\runas\command" /v "IsolatedCommand" /t REG_SZ /d "\"%%1\" %%*" /f >NUL 2>&1
echo.
echo Done.
echo.
Pause
exit
=====================================================================================
:IsAdmin
Reg 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