I need to perform different tasks in a bat file based on the windows
version. So, do I get the OS version?
In addition to Paul's:
for /f "tokens=1* Delims=[" %%u in ('ver') do set Version=%%v
set Version=%version:~8,3%
you can also retrieve it from the registry.
It is in the CurrentVersion Value Name, a REG_SZ data type, at
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
Regedit /a "%TEMP%\cv.tmp" "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
for /f "Tokens=2 Delims==" %%v in ('type "%TEMP%\cv.tmp"^|FIND /I "CurrentVersion"^|FIND "."') do (
if %%v GEQ "3.5" if %%v LSS "9.9" set Version=%%v
)
set Version=%Version:"=%
set Version=%Version:~0,3%
or, using REG.EXE, built into XP and later, or installed from the Support Tools on the W2K CD-ROM:
set Version=0.0
for /f "Tokens=3" %%v in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /V CurrentVersion') do set Version=%%v
set Version=%Version:~0,3%
Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com