Determine which Windows OS version is running

  • HOME
  • >
  • WINDOWS
  • >
  • Determine which Windows OS version is running
Last Updated: 

👉 This post was initially written in 2006 and refered to specific software versions. When tunning your system, always consider which version you are running. Information below may be outdated. Use it at your own risk.

Many DOS commands in the 32-bit versions of Windows are similar but support different parameters, different commands or using different registry key name. Thus, if you wish to write a batch file that can run on different types of machines, it may prove beneficial to determine the version of Windows on which the batch file is running. This way the batch file can execute commands appropriate to the operating system.

The simpliest way to know the OS Version is to run the universal windows DOS command "VER" then using "FIND" on it returned result.

@echo off

ver | find "2003″ > nul
if %ERRORLEVEL% == 0 goto v2003

ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto vxp

ver | find "2000″ > nul
if %ERRORLEVEL% == 0 goto v2000

ver | find "NT" > nul
if %ERRORLEVEL% == 0 goto vnt

echo Unknow OS Version.
goto exit

:v2003
:Run Windows 2003 specific commands here.
goto exit

:vxp
:Run Windows XP specific commands here.
goto exit

:v2000
:Run Windows 2000 specific commands here.
goto exit

:vnt
:Run Windows NT-specific commands here.
goto exit

:exit

You can easily add the support of other versions of Windows as necessary or set an environment variable based on the version of Windows detected.

Related windows posts that you may like
Running Bash script with Ubuntu on Windows 10 using WSL
No-hassle! Learn how to run Bash on Windows by installing your favorite Linux distribution natively on Windows 10 using Windows Subsystem for Linux, aka WSL.
Files and directories user permissions on Windows XP
How to solve files and directories permissions on windows XP using CACLS.
CLI workaround for Windows XP : Doing a pause in a batch script
How to workaround the lack of command line to sleep or wait some period of time on windows XP. This tips shows, first a batch example using the ping command, second using the Windows Server 2003 Ressource Kit tools with the SLEEP command.