[Batch] Identify OS.

Discussion in 'Scripting' started by DARKOR04, Jan 31, 2011.

  1. DARKOR04

    DARKOR04 MDL Tester/Developer

    Jul 5, 2010
    497
    909
    10
    #1 DARKOR04, Jan 31, 2011
    Last edited by a moderator: Apr 20, 2017
    You can add this in any part of the batch you are working on.

    Code:
    :oscheck
    for /f "tokens=2 delims==" %%A in ('"WMIC OS LIST BRIEF /format:list"') do set os=%%A
    if %os% equ 5.1.2600 goto:windowsxp
    if %os% equ 6.0.6002 goto:windowsvista
    if %os% equ 6.1.7600 goto:windows7
    
    :windowsxp
    -code here-
    
    :windowsvista 
    -code here-
    
    :windows7
    -code here-
    
    :end
    exit /b
    Or use it this way to display Operating System Build Number.
    Code:
    @echo off
    for /f "tokens=2 delims==" %%A in ('"WMIC OS LIST BRIEF /format:list"') do set os=%%A
    echo. OS Build Number: %os%
    pause
    or this way to display Windows name and build number. in my case the output is: (Working on Windows 7 - 6.1.7600)

    Code:
    @echo off
    for /f "tokens=2 delims==" %%A in ('"WMIC OS LIST BRIEF /format:list"') do set build=%%A
    if %build% equ 5.1.2600 set name=Windows XP SP3
    if %build% equ 6.0.6002 set name=Windows Vista SP2
    if %build% equ 6.1.7600 set name=Windows 7
    echo. Working OS:%name% - %build%
    pause
    if for some reason you have the leaked Win 7 SP1 and want it to work on both With or without SP1 then change this:
    Code:
    if %build% equ 6.1.7600 set name=Windows 7
    for this:
    Code:
    if %build% geq 6.1.7600 set name=Windows 7
    equ = equal
    geq = greater or equal
     
  2. renoOo

    renoOo MDL Novice

    Jan 29, 2011
    43
    13
    0
    Good trick. I do something else for the same result

    call :WinVer
    echo %versionbase%
    echo %version%
    pause
    if %versionbase% GEQ 6 goto test

    :WinVer
    SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
    FOR /f "tokens=1,2,3* delims=." %%a IN ('ver') DO (
    SET WVer=%%a
    SET WVer=!WVer:~-1!
    SET WVer=!WVer!.%%b.%%c
    SET WVer=!WVer:]=!
    )
    set /a Wverbase = WVer+0
    ENDLOCAL & SET versionbase=%Wverbase%& SET version=%Wver%
    goto:eof