Determine which Windows OS version is running

DOS - Windows Batch Files, Tips Add comments

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.

Share this post with your network :These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Login