0

I'm making "BatchGameHub" for windows 10, and right now I'm making installer in .batch, but I don't know how to check windows version (10, 8, 7) and with support with if command. Example what I mean: (Command to check version)

if %winversion%== 10 goto start
goto win_not_compatible

:win_not_compatible
echo.
echo Your windows version cannot run gamehub!
echo [ Press any key to cancel installer... ]
echo.
pause>null
exit
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • 1
    Check out the [`ver` command](http://ss64.com/nt/ver.html). To capture its result use a [`for /F` loop](http://ss64.com/nt/for_f.html). – aschipfl Mar 27 '18 at 12:53

3 Answers3

1

Check the windows build numbers - https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx

And try this:

@echo off

for /f "tokens=4,5 delims=,. "  %%a in ('ver') do set "build_n=%%a.%%b"

set "Windows10=10.0"
set "Windows8.1=6.3"
set "Windows8=6.2"
set "Windows7=6.1"
set "WindowsVista=6.0"

if exist "%windir%\sysWOW64\" (
 set "bitness=64bit"
) else (
 set "bitness=32bit"
)

if not "%Windows10%"=="%build_n%" (
  goto :not_supported
) else (
  goto :start
)

:not_supported

echo not supported
exit /b 1

:start
pause
npocmaka
  • 55,367
  • 18
  • 148
  • 187
1

To do what your question asks using WMIC this should work:

@Echo Off
Set "OV="
For /F "Skip=1 Tokens=*" %%A In (
    'WMIC OS Where "Version<'4'" Get Version 2^>Nul') Do For %%B In (%%A
) Do Set "OV=%%A"
If Defined OV GoTo Start
Echo=
Echo Your windows version cannot run gamehub!
Echo [ Press any key to cancel installer... ]
Echo=
Pause>Nul
Exit /B

:Start

I used < with 4 to GoTo Start only on Windows 10, because a string comparison will find that the first character, 1 is less than 4 etc. (Windows 10 or newer.)

Compo
  • 36,585
  • 5
  • 27
  • 39
0

A batch file like this could be used:

@echo off
setlocal EnableExtensions DisableDelayedExpansion

rem Get version of Windows enclosed in square brackets from command VER.
for /F "tokens=2 delims=[]" %%I in ('ver') do set "VersionWindows=%%I"

rem Get major and minor version and build number from version information.
for /F "tokens=2-4 delims=. " %%A in ("%VersionWindows%") do (
    set "VersionMajor=%%A"
    set "VersionMinor=%%B"
    set "VersionBuild=%%C"
)

if %VersionMajor% LSS 10 (
    echo/
    echo Your windows version cannot run gamehub!
    echo/
    echo [Press any key to cancel installer... ]
    echo/
    endlocal
    pause >nul
    exit
)

rem Other commands for installation like:

set "ProcessArchitecture=%PROCESSOR_ARCHITECTURE:~-2%"
if %ProcessArchitecture% == 86 (
    set "ProcessArchitecture=32"
) else (
    if exist %SystemRoot%\Sysnative\cmd.exe set "ProcessArchitecture=32"
)

echo Your are using Windows version %VersionMajor%.%VersionMinor%.%VersionBuild% %PROCESSOR_ARCHITECTURE%
echo The installation process is running in %ProcessArchitecture%-bit environment.

endlocal

Please take into account the Microsoft documentation pages:

It depends on the process starting the batch file if the batch file is executed by 32-bit cmd.exe in %SystemRoot%\SysWOW64 or by 64-bit cmd.exe in %SystemRoot%\System32 on Windows x64 (AMD64).

The following Wikipedia articles could be also helpful for this coding task:

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

  • echo /?
  • endlocal /?
  • exit /?
  • for /?
  • if /?
  • pause /?
  • rem /?
  • set /?
  • setlocal /?
  • ver /?

And the name of the device NUL is nul with just one L. A line like pause>null results in redirecting the message into file with name null instead of device NUL. See also the Microsoft documentation pages Using Command Redirection Operators and Naming Files, Paths, and Namespaces containing among lots of other useful information also a list of device names.

And last but not least read also DosTips forum topic ECHO. FAILS to give text or blank line - Instead use ECHO/ and avoid in future echo. in batch files and read about debugging a batch file.

Mofi
  • 46,139
  • 17
  • 80
  • 143