@echo off

cd /D "%~dp0"

set kernelname=Windows Vista Extended Kernel, February 2021 Release

title Windows Vista Extended Kernel Setup

echo This is the installer for the Core Files of the %kernelname%.
echo.
echo This program must be run with administrative privileges.
echo.
echo Ensure that April 2017 updates (or later) are installed before continuing.
pause

:continue
if not exist "%cd%\ntextx86.dll" (
echo.
echo Error: ntextx86.dll is missing. Setup will now close.
pause
exit
)
if not exist "%cd%\ntk32.dll" (
echo.
echo Error: ntk32.dll is missing. Setup will now close.
pause
exit
)
if not exist "%cd%\kernel32.dll" (
echo.
echo Error: kernel32.dll is missing. Setup will now close.
pause
exit
)

if not exist "%cd%\user32.dll" (
echo.
echo Error: user32.dll is missing. Setup will now close.
pause
exit
)

if not exist "%cd%\shell32.dll" (
echo.
echo Error: shell32.dll is missing. Setup will now close.
pause
exit
)

if not exist "%cd%\ole32.dll" (
echo.
echo Error: ole32.dll is missing. Setup will now close.
pause
exit
)

if not exist "%cd%\uxtheme.dll" (
echo.
echo Error: uxtheme.dll is missing. Setup will now close.
pause
exit
)

if not exist "%cd%\dwmapi.dll" (
echo.
echo Error: dwmapi.dll is missing. Setup will now close.
pause
exit
)

if not exist "%cd%\kernel32x86.dll" (
echo.
echo Error: kernel32x86.dll is missing. Setup will now close.
pause
exit
)

if not exist "%cd%\winload.efi" (
echo.
echo Error: winload.efi is missing. Setup will now close.
pause
exit
)

if not exist "%cd%\winload.exe" (
echo.
echo Error: winload.exe is missing. Setup will now close.
pause
exit
)

if not exist "%cd%\ntoskrnl.exe" (
echo.
echo Error: ntoskrnl.exe is missing. Setup will now close.
pause
exit
)

if not exist "%cd%\ntdll.dll" (
echo.
echo Error: ntdll.dll is missing. Setup will now close.
pause
exit
)


cls

echo Copying files...



takeown /f %windir%\system32\kernel32.dll
takeown /f %windir%\system32\user32.dll
takeown /f %windir%\system32\shell32.dll
takeown /f %windir%\system32\ole32.dll
takeown /f %windir%\system32\winload.exe
takeown /f %windir%\system32\winload.efi
takeown /f %windir%\system32\ntoskrnl.exe
takeown /f %windir%\system32\ci.dll
takeown /f %windir%\system32\ntdll.dll
takeown /f %windir%\system32\dwmapi.dll
takeown /f %windir%\system32\uxtheme.dll
takeown /f %windir%\syswow64\kernel32.dll



icacls %windir%\system32\kernel32.dll /grant "%username%":F
icacls %windir%\system32\user32.dll /grant "%username%":F
icacls %windir%\system32\shell32.dll /grant "%username%":F
icacls %windir%\system32\ole32.dll /grant "%username%":F
icacls %windir%\system32\dwmapi.dll /grant "%username%":F
icacls %windir%\system32\uxtheme.dll /grant "%username%":F
icacls %windir%\syswow64\kernel32.dll /grant "%username%":F
icacls %windir%\system32\winload.exe /grant "%username%":F
icacls %windir%\system32\winload.efi /grant "%username%":F
icacls %windir%\system32\ntoskrnl.exe /grant "%username%":F
icacls %windir%\system32\ntdll.dll /grant "%username%":F
icacls %windir%\system32\ci.dll /grant "%username%":F

bcdedit /set {current} nointegritychecks yes


if exist "%windir%\syswow64\ntk32.dll.bak" (
del %windir%\syswow64\ntk32.dll.bak
goto krnl64chk
) else (
goto krnl64chk
)

:krnl64chk

if exist "%windir%\system32\kernel32.dll.bak" (
del %windir%\system32\kernel32.dll.bak
goto krnl86chk
) else (
goto krnl86chk
)

:krnl86chk

if exist "%windir%\syswow64\kernel32.dll.bak" (
del %windir%\syswow64\kernel32.dll.bak
goto user32chk
) else (
goto user32chk
)

:user32chk

if exist "%windir%\system32\user32.dll.bak" (
del %windir%\system32\user32.dll.bak
goto shell32chk
) else (
goto shell32chk
)

:shell32chk

if exist "%windir%\system32\shell32.dll.bak" (
del %windir%\system32\shell32.dll.bak
goto ole32chk
) else (
goto ole32chk
)

:ole32chk

if exist "%windir%\system32\ole32.dll.bak" (
del %windir%\system32\ole32.dll.bak
goto dwmapichk
) else (
goto dwmapichk
)

:dwmapichk

if exist "%windir%\system32\dwmapi.dll.bak" (
del %windir%\system32\dwmapi.dll.bak
goto uxthemechk
) else (
goto uxthemechk
)

:uxthemechk

if exist "%windir%\system32\uxtheme.dll.bak" (
del %windir%\system32\uxtheme.dll.bak
goto ntextx86ren
) else (
goto ntextx86ren
)


:ntextx86ren
if exist "%windir%\syswow64\ntext.dll" (
rename %windir%\syswow64\ntext.dll ntext.dll.bak
goto k32x86ren
) else (
goto k32x86ren
)

:k32x86ren
if exist "%windir%\syswow64\ntk32.dll" (
rename %windir%\syswow64\ntk32.dll ntk32.dll.bak
goto winloadefichk
) else (
goto winloadefichk
)

:winloadefichk
if exist "%windir%\system32\winload.efi.bak" (
del %windir%\system32\winload.efi.bak
goto winloadexechk
) else (
goto winloadexechk
)

:winloadexechk
if exist "%windir%\system32\winload.exe.bak" (
del %windir%\system32\winload.exe.bak
goto ntoskrnlchk
) else (
goto ntoskrnlchk
)

:ntoskrnlchk
if exist "%windir%\system32\ntoskrnl.exe.bak" (
del %windir%\system32\ntoskrnl.exe.bak
goto ntdllchk
) else (
goto ntdllchk
)

:ntdllchk
if exist "%windir%\system32\ntdll.dll.bak" (
del %windir%\system32\ntdll.dll.bak
goto cichk
) else (
goto cichk
)

:cichk
if exist "%windir%\system32\ci.dll.bak" (
del %windir%\system32\ci.dll.bak
goto rename
) else (
goto rename
)




:rename

rename %windir%\system32\kernel32.dll kernel32.dll.bak
rename %windir%\system32\user32.dll user32.dll.bak
rename %windir%\system32\shell32.dll shell32.dll.bak
rename %windir%\system32\ole32.dll ole32.dll.bak
rename %windir%\system32\dwmapi.dll dwmapi.dll.bak
rename %windir%\system32\uxtheme.dll uxtheme.dll.bak
rename %windir%\syswow64\kernel32.dll kernel32.dll.bak
rename %windir%\system32\ntdll.dll ntdll.dll.bak
rename %windir%\system32\ci.dll ci.dll.bak
rename %windir%\system32\ntoskrnl.exe ntoskrnl.exe.bak
rename %windir%\system32\winload.efi winload.efi.bak
rename %windir%\system32\winload.exe winload.exe.bak

copy %cd%\ntextx86.dll %windir%\syswow64\ntext.dll
copy %cd%\ntk32.dll %windir%\syswow64\ntk32.dll
copy %cd%\kernel32.dll %windir%\system32\kernel32.dll
copy %cd%\user32.dll %windir%\system32\user32.dll
copy %cd%\shell32.dll %windir%\system32\shell32.dll
copy %cd%\ole32.dll %windir%\system32\ole32.dll
copy %cd%\dwmapi.dll %windir%\system32\dwmapi.dll
copy %cd%\uxtheme.dll %windir%\system32\uxtheme.dll
copy %cd%\kernel32x86.dll %windir%\syswow64\kernel32.dll
copy %cd%\ntdll.dll       %windir%\system32\ntdll.dll
copy %cd%\ntoskrnl.exe    %windir%\system32\ntoskrnl.exe
copy %cd%\winload.exe     %windir%\system32\winload.exe
copy %cd%\winload.efi     %windir%\system32\winload.efi
copy %cd%\ci.dll       %windir%\system32\ci.dll


echo %kernelname%, is installed.

pause
exit