@echo off
setlocal EnableDelayedExpansion

:: ============================================================
:: Windows Version & Architecture Detection Script
:: Supports: Windows 10 (32/64-bit), Windows 11 (64-bit & ARM)
:: Uses reg query instead of wmic (wmic removed in Windows 11)
:: ============================================================

:: --- Read CurrentBuild from the Registry ---
set "OS_BUILD="
for /f "tokens=3" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuild 2^>nul') do (
    set "OS_BUILD=%%i"
)

:: --- Read ProductName from the Registry (e.g. "Windows 10 Pro") ---
set "OS_CAPTION="
for /f "tokens=2,*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName 2^>nul') do (
    set "OS_CAPTION=%%j"
)

:: --- If registry reads failed, this is not a supported Windows version ---
if not defined OS_BUILD   goto :NOT_SUPPORTED
if not defined OS_CAPTION goto :NOT_SUPPORTED

:: --- Detect ARM via environment variables ---
:: PROCESSOR_ARCHITECTURE = ARM64 on native ARM64 cmd sessions
:: PROCESSOR_ARCHITEW6432 = ARM64 when a 32-bit process runs on ARM64
set "IS_ARM=0"
if /i "%PROCESSOR_ARCHITECTURE%"=="ARM64"   set "IS_ARM=1"
if /i "%PROCESSOR_ARCHITEW6432%"=="ARM64"   set "IS_ARM=1"

:: --- Detect 32-bit OS via environment variables ---
:: On a true 32-bit OS, PROCESSOR_ARCHITECTURE=x86 and
:: PROCESSOR_ARCHITEW6432 is undefined
set "IS_32BIT=0"
if /i "%PROCESSOR_ARCHITECTURE%"=="x86" (
    if not defined PROCESSOR_ARCHITEW6432 set "IS_32BIT=1"
)

:: --- Convert build number to integer for comparison ---
set /a BUILD_NUM=!OS_BUILD!

:: ============================================================
:: Windows 11 Detection  (Build >= 22000)
:: ============================================================
if !BUILD_NUM! GEQ 22000 (
    echo Detected: Windows 11
    if "!IS_ARM!"=="1" (
        echo Architecture: ARM64
        echo Launching wincheckarm64.bat ...
        cd WindowsARM
        start "" "Systemcheck.exe"
	exit
    ) else (
        echo Architecture: 64-bit
        echo Launching wincheck64.bat ...
	cd windows64
       start "" "systemcheck.exe"
       exit

    )
    goto :END
)

:: ============================================================
:: Windows 10 Detection  (Build 10240 - 19045)
:: ============================================================
if !BUILD_NUM! GEQ 10240 (
    echo !OS_CAPTION! | findstr /i "Windows 10" >nul 2>&1
    if not errorlevel 1 (
        echo Detected: Windows 10
        if "!IS_32BIT!"=="1" (
            echo Architecture: 32-bit
            echo Launching wincheck.bat ...
	    cd windows
            start "" "systemcheck.exe"
            exit
           
        ) else (
            echo Architecture: 64-bit
            echo Launching wincheck64.bat ...
            cd windows64
	    start "" "systemcheck.exe"
            exit
        )
        goto :END
    )
)

:: ============================================================
:: No supported version matched
:: ============================================================
:NOT_SUPPORTED
echo No Supported Windows Version has been detected!
PAUSE
:END
endlocal
