[windows] Get Windows version in a batch file

The first line forces a WMI console installation if required on a new build. WMI always returns a consistent string of "Version=x.x.xxxx" so the token parsing is always the same for all Windows versions.

Parsing from the VER output has variable text preceding the version info, making token positions random. Delimiters are only the '=' and '.' characters.

The batch addition allows me to easily check versions as '510' (XP) up to '10000' for Win10. I don't use the Build value.

Setlocal EnableDelayedExpansion

wmic os get version /value 1>nul 2>nul

if %errorlevel% equ 0 (
   for /F "tokens=2,3,4 delims==." %%A In ('wmic os get version /value')  Do (
      (Set /A "_MAJ=%%A")
      (Set /A "_MIN=%%B")
      (Set /A "_BLD=%%C")
      )
    (Set /A "_OSVERSION=!_MAJ!*100")
    (Set /A "_OSVERSION+=!_MIN!*10")
    )

endlocal

Examples related to windows

"Permission Denied" trying to run Python on Windows 10 A fatal error occurred while creating a TLS client credential. The internal error state is 10013 How to install OpenJDK 11 on Windows? I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? git clone: Authentication failed for <URL> How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" XCOPY: Overwrite all without prompt in BATCH Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory how to open Jupyter notebook in chrome on windows Tensorflow import error: No module named 'tensorflow'

Examples related to batch-file

'ls' is not recognized as an internal or external command, operable program or batch file '' is not recognized as an internal or external command, operable program or batch file XCOPY: Overwrite all without prompt in BATCH CanĀ“t run .bat file under windows 10 Execute a batch file on a remote PC using a batch file on local PC Windows batch - concatenate multiple text files into one How do I create a shortcut via command-line in Windows? Getting Error:JRE_HOME variable is not defined correctly when trying to run startup.bat of Apache-Tomcat Curl not recognized as an internal or external command, operable program or batch file Best way to script remote SSH commands in Batch (Windows)

Examples related to operating-system

Context.startForegroundService() did not then call Service.startForeground() Fork() function in C python: get directory two levels up Find Process Name by its Process ID Best way to find os name and version in Unix/Linux platform How to run a program without an operating system? How to make parent wait for all child processes to finish? Get operating system info Running windows shell commands with python What are the differences between virtual memory and physical memory?