Search code examples
windowsbatch-fileversion

How do I make it so that the program will exit if the user's Windows version is lower than Windows 8?


I have looked everywhere I could, and I found nothing that could help me.

The current code I have is

    if "%version%" == "6.0" echo Windows Vista is not supported by this program, as the commands this program uses are not in Windows Vista.
pause
exit

if "%version%" == "6.1" echo Windows 7 is not supported by this program, as the commands this program uses are not in Windows 7. 
pause
exit

if "%version%" == "6.2" echo Windows 8 support with this program has not been tested, this program may not work if some commands that are used in this program are not in Windows 8, If you would like to continue, please press "1", press "0" if you would like to exit.
choice /c ecsf /m "Choose your option."
if %ERRORLEVEL% EQU 1 goto MENU
if %ERRORLEVEL% EQU 0 exit

if "%version%" == "6.3" echo Windows 8.1 support with this program has not been tested, this program may not work if some commands that are used in this program are not in Windows 8, If you would like to continue, please press "1", press "0" if you would like to exit.
choice /c ecsf /m "Choose your option."
if %ERRORLEVEL% EQU 1 goto MENU
if %ERRORLEVEL% EQU 0 exit

Solution

  • Windows 8 release version is 6.2.* without taking into account the patches. So you need an integer comparison of the version without the patches and the version to be bigger than 61. You can use:

    @echo off
    
    for /f "tokens=2 delims=[" %%# in ('ver') do (
        for /f "tokens=2,3 delims=. " %%a in ("%%#") do set r_vers=%%a%%b
    )
    
    echo %r_vers%
    
    if %r_vers% LSS 62 (
      echo you need at least Windows 8
      pause
      exit /b 1
    )
    
    echo continue with the script
    pause