Determine which Windows OS version is running
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.
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.
:Run Windows 2003 specific commands here.
:Run Windows XP specific commands here.
:Run Windows 2000 specific commands here.
:Run Windows NT-specific commands here.
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.