Windows version

  • Thread starter Thread starter BigMan
  • Start date Start date
B

BigMan

I need to perform different tasks in a bat file based on the windows
version. So, do I get the OS version?
 
Hello, BigMan:
On Sun, 13 Feb 2005 20:50:33 +0200: you wrote...

B> I need to perform different tasks in a bat file based on the windows
B> version. So, do I get the OS version?
B>

ver

Regards, Paul R. Sadowski [MVP].
 
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
 
BigMan said:
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 the answers already given, I wrote two freeware tools
called osver.exe and osverex.exe that return the OS version as an exit
code. (Osverex.exe does more granular checking but requires Windows NT
4.0 SP6 or later.)

You can get them from my "Windows Admin Script Tools" package:

http://www.cybermesa.com/~bstewart/wast.html
 
Back
Top