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.

Comments