1.

Solve : Determining Win Version (and keeping it simple)?

Answer»

Hi,

I am TRYING to create a batch file that I can call from other batch files when I need to know the Windows version. I had intended to USE this:
Code: [Select]REG QUERY "hklm\software\microsoft\windows nt\currentversion" /v CurrentVersion
Unfortunately, I am on Windows 7 and this is still returning 6.1. I am guessing that this reg string is obsolete?

I have searched Google and found some examples that seem really klugey. Is there a way to just simply get this info so a batch can branch based on it?

Thanks!


Windows 7 version 6.1.

EDIT:

Windows 2000 is 5.0, XP is 5.1, Vista is 6.0, and 7 is 6.1

you could explicitly test for each version number, to determine the platform.Thanks. Ugh.

So, I've seen examples that do something like this (abbridged):
Code: [Select]echo off
ver | find "5.1." > nul
if %ERRORLEVEL% == 0 goto WinXP
ver | find "6.1." > nul
if %ERRORLEVEL% == 0 goto Win7

goto Undetermined

:WinXP
echo Windows XP
goto EXIT

:Win7
echo Windows 7
goto exit

:Undetermined
echo Machine undetermined.

:exit
I also understand that Win Server 2008 is also version 6.1, but that shouldn't be a problem for me. What I would really like to do instead of generating a text description of the OS, is parse out the actual version string and get a number.

I'd like to be able to say, if the version is less than 6.0 (Vista) then do one thing. Otherwise, do the other. Is it possible to declare a floating point variable and then convert a subsection of a string to it via a batch file?

Thanks in advance for any info. Quote

What I would really like to do instead of generating a text description of the OS, is parse out the actual version string and get a number.

I'd like to be able to say, if the version is less than 6.0 (Vista) then do one thing. Otherwise, do the other. Is it possible to declare a floating point variable and then convert a subsection of a string to it via a batch file?

You only get integer variables in batch. Anyhow the version numbers have more than one dot.

The VER command...

Windows 2000

Code: [Select]Microsoft Windows 2000 [Version 5.00.2195]
Windows XP

Code: [Select]Microsoft Windows XP [Version 5.1.2600]
Windows 7

Code: [Select]Microsoft Windows [Version 6.1.7600]
Code: [Select]echo off

for /f "tokens=1,2,3 delims=[]" %%V in ('ver') do set versionstring=%%W
for /f "tokens=1,2 delims= " %%A in ("%versionstring%") do set versionnumber=%%B
for /f "delims=." %%M in ("%versionnumber%") do set majorversionnumber=%%M

echo version string       = %versionstring%
echo full version number  = %versionnumber%
echo major version number = %majorversionnumber%

REM you have EQU NEQ LEQ GEQ LSS GTR comparison operators
REM Type IF /? at the prompt to see documentation

if %majorversionnumber% LSS 6 (
    echo Version number smaller than 6
) else (
    echo Version number greater than or equal to 6
)


Code: [Select]version string       = Version 5.1.2600
full version number  = 5.1.2600
major version number = 5
Version number less than 6



see here!

http://windowsteamblog.com/blogs/developers/archive/2009/08/05/version-checking-just-don-t-do-it.aspxThanks for both posts Salmon. The only incompatibility that I am trying to avoid is related to pushing some shortcuts into the All Users STARTUP menu. So yeah. It is probably wiser for me to just look for the Win7 folder. If it exists, use it. Otherwise assume WinXP.

Granted, this is very weak. But this is for a highly controlled environment where it should only be one of these two OSes. And, the same folders were used from Win2K through XP, and Vista through Win7. So it should work anyway if someone is out of OS spec.



Discussion

No Comment Found