@echo off
setlocal EnableDelayedExpansion

:: Ensure administrative privileges
net session >nul 2>&1
if %errorLevel% neq 0 exit /b

:: ==========================================
:: SECTION 1: CUSTOM HOOKS & DISK CLOAKING
:: ==========================================
set "diskpart_cmd=%temp%\remove_cidata.txt"

echo list volume > "%diskpart_cmd%"
for /f "tokens=2,3,4" %%A in ('diskpart /s "%diskpart_cmd%" 2^>nul ^| findstr /i "cidata"') do (
    set "vol_num=%%A"
    set "drive_letter=%%B"
)

if not "%vol_num%"=="" (
    (
        echo select volume %vol_num%
        echo remove letter=%drive_letter%
    ) > "%diskpart_cmd%"
    diskpart /s "%diskpart_cmd%" >nul 2>&1
)
del "%diskpart_cmd%" 2>nul

:: Hide the drive from File Explorer & block path access
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "NoDrives" /t REG_DWORD /d 33554432 /f >nul 2>&1
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "NoViewOnDrive" /t REG_DWORD /d 33554432 /f >nul 2>&1

:: Disable the driver service 
reg add "HKLM\System\CurrentControlSet\Services\cdrom" /v "Start" /t REG_DWORD /d 4 /f >nul 2>&1

:: Hide the CD-ROM hardware class from Device Manager
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4d36e965-e325-11ce-bfc1-08002be10318}" /v "NoDisplayClass" /t REG_SZ /d "1" /f >nul 2>&1


:: ==========================================
:: SECTION 2: DISM EVAL TO FULL CONVERSION
:: ==========================================
:: Target: Windows Server 2022 Datacenter
:: Key: Official Microsoft GVLK (KMS) Client Key for Server 2022 Datacenter
DISM /online /Set-Edition:ServerDatacenter /ProductKey:WX4NM-KYWYW-QJJR4-XV3QB-6VMF3 /AcceptEula /NoRestart


:: ==========================================
:: SECTION 3: KMS ACTIVATION & AUTO-RENEWAL
:: ==========================================
:: Download and run MAS unattended: 
:: /KMS-Act flags activation, /KMS-SetupTask ensures the renewal scheduled task is created
powershell -NoProfile -ExecutionPolicy Bypass -Command "& ([ScriptBlock]::Create((irm https://get.activated.win))) /KMS-Act /KMS-SetupTask"


:: ==========================================
:: SECTION 4: SELF-DESTRUCTION & FINAL REBOOT
:: ==========================================
:: Spawn a separate background cmd process to delete this file and reboot the VPS safely
start /b "" cmd /c "timeout /t 5 /nobreak >nul & del /f /q "%~f0" & shutdown /r /t 0 /f"

exit /b