3

I have a (test) batch file with this code

If Exist "C:\Users\All Users\ntuser.dat" Goto Win 7 If Exist "C:\Documents and Settings\All Users\ntuser.dat" Goto Win XP

:Win 7 will write here the parameters which'll run on win7

C:\w7\test.txt

:Win XP

will write here the parameters which'll run on winxp

and so the same with other os + os architecture

it's working, but i need to add more os identify options.. I need that batch file to identify os version, architecture (Windows 2003R2 x64 only, Windows Xp x32 and x64, Windows Vista x32 and x64, Windows 7 x32 and x64, Windows 8 x32 and x64)

Thank you very much in Advanced!

Vako
  • 113
  • 5

2 Answers2

5

there is a nice solution from Aacini here on SO, but can't find it now and post it from my "library":

@echo off
setlocal EnableDelayedExpansion

::Identify OS
for /F "delims=" %%a in ('ver') do set ver=%%a
set Version=
for %%a in (95=95 98=98 ME=ME NT=NT 2000=2000 5.1.=XP 5.2.=2003 6.0.=Vista 6.1.=7 6.2.=8) do (
    if "!Version!" equ "this" (
        set Version=Windows %%a
    ) else if "!ver: %%a=!" neq "%ver%" (
        set Version=this
    )
)

::Identify bit
if exist "%SYSTEMDRIVE%\Program Files (x86)" (
    set Type=64 bit
) else (
    set Type=32 bit
)

::Display result
echo %Version% %Type%
goto :eof


::Goto right version
goto %Version: =_%


:Windows_8
echo Windows 8

:Windows_7
echo Windows 7

© Aacini at dostips

Community
  • 1
  • 1
Endoro
  • 37,015
  • 8
  • 50
  • 63
3

Just use WMIC from command line or batch file. Much easier, shorter and you can parse it.

wmic OS get OSArchitecture,caption
Panama Jack
  • 24,158
  • 10
  • 63
  • 95
  • Thanks You are correct that it will not work on `XP Home` but **will** work on `XP Professional`. Most companies don't use Home edition. I assume, most individuals looking for all the versions of Windows aren't using home addition on a tech site. :) – Panama Jack Jun 27 '13 at 18:48
  • @Endoro that reply was for you. – Panama Jack Jun 27 '13 at 18:49