How to determine the minor Win10 build number via batch?

Discussion in 'Windows 10' started by RobertJ, Nov 11, 2016.

  1. RobertJ

    RobertJ MDL Senior Member

    Apr 4, 2014
    318
    79
    10
    #1 RobertJ, Nov 11, 2016
    Last edited: Nov 11, 2016
    winver's dialog displays 14393.447 for example, but ver at the command line only displays 10.0.14393.

    What's the easiest and most reliable way to get the 447 portion using a batch file that'll work on all Win10 versions?

    Edit: Sigh... To clarify for those who can't understand what "via batch" means, I need the minor build number accessible for further processing in a batch file/script.
     
  2. dhjohns

    dhjohns MDL Guru

    Sep 5, 2013
    3,262
    1,731
    120
    Open command prompt as administrator, and type winver.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. GOD666

    GOD666 MDL Expert

    Aug 1, 2015
    1,958
    2,061
    60
    Ha ha ha ha :worthy:


    It's funny, because it's also true.
     
  4. RobertJ

    RobertJ MDL Senior Member

    Apr 4, 2014
    318
    79
    10
    #4 RobertJ, Nov 11, 2016
    Last edited: Nov 11, 2016
    (OP)
    Ok, so I'm not sure whether you're simply trying to crack a silly joke or being serious. If the latter, besides the fact that winver can be launched from a non admin cmd prompt too, how do you propose to access its output via a batch script?

    If I simply wanted to look up the number in a GUI dialog why would I bother with a batch file? Honestly, this being MDL I didn't really think I'd need to spell out what "via batch" meant...
     
  5. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    6,222
    22,280
    210
    #5 Alphawaves, Nov 12, 2016
    Last edited by a moderator: Apr 20, 2017
    Not too good with cmd.. but powershell:

    Code:
    function Get-RegistryValue($key, $value) {
    (Get-ItemProperty $key $value).$value
    }
    $a1 = Get-RegistryValue "HKLM:\Software\Microsoft\Windows NT\CurrentVersion" UBR
    Write-Host $a1
    Hope it helps.. :)
     
  6. qwerty12

    qwerty12 MDL Novice

    Aug 31, 2010
    49
    68
    0
    #6 qwerty12, Nov 12, 2016
    Last edited by a moderator: Apr 20, 2017
  7. Garbellano

    Garbellano MDL Addicted

    Aug 13, 2012
    947
    248
    30
    #7 Garbellano, Nov 12, 2016
    Last edited by a moderator: Apr 20, 2017
    Code:
    @echo OFF
    setlocal ENABLEEXTENSIONS
    set REG_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    set KEY_NAME=CurrentBuild
    set KEY_SUBBUILD=UBR
    
    FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %REG_NAME% /v %KEY_NAME% 2^>nul`) DO (@echo %%C) 
    FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %REG_NAME% /v %KEY_SUBBUILD% 2^>nul`) DO (@echo %%C)
    
     
  8. RobertJ

    RobertJ MDL Senior Member

    Apr 4, 2014
    318
    79
    10
    #8 RobertJ, Nov 12, 2016
    Last edited by a moderator: Apr 20, 2017
    (OP)
  9. farukkaraca

    farukkaraca MDL Member

    Sep 27, 2009
    169
    97
    10
    #9 farukkaraca, Nov 12, 2016
    Last edited by a moderator: Apr 20, 2017
    You can use this in a batch file to find minor build

    Code:
    @ECHO OFF
    SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
    FOR /F "tokens=2 delims=." %%A in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildLabEx') Do (Set Minor=%%A)
    Echo:Minor Build = %Minor%
    Pause
    Exit
     
  10. RobertJ

    RobertJ MDL Senior Member

    Apr 4, 2014
    318
    79
    10
    #10 RobertJ, Nov 12, 2016
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thanks, but for now I prefer the UBR DWORD mentioned above since it specifically contains only the minor build number. I just need to confirm that it's present right from Win10 RTM onwards and in various versions of the OS. If not then I'll check BuildLabEx but probably the file version check would be most reliable even though it's slower than reg access.
     
  11. qwerty12

    qwerty12 MDL Novice

    Aug 31, 2010
    49
    68
    0
    I only have 14393 ISOs lying around, sorry, so I can't check the actual behaviour of Windows on previous versions, but I think reading UBR from the registry is the best way, indeed, compared to the file version check, as Microsoft themselves read UBR etc. in winver (well, ShellAbout) on 14393 to determine the displayed version information.

    On 10240 (I found a copy of its shell32.dll on dll-files.com), ShellAbout uses GetVersionExW and if you look at screenshots of 10240's about dialog on the Internet, you'll notice the lack of a minor build number on them. I don't think GetVersionExW can display such information, as I couldn't find a member containing the same value as the UBR registry value in any of the fields of RTL_OSVERSIONINFOEXW (though, I am very inexperienced with the WinAPI, so take from that what you will).

    In 10.0.10586.11's shell32.dll, ShellAbout reads UBR there too. I can only assume that it's the same for 10.0.10586.494's shell32.dll.
     
  12. javaspain

    javaspain MDL Member

    Jul 29, 2009
    191
    98
    10
    reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" | findstr BuildLabEx
     
  13. Full inu

    Full inu MDL Addicted

    Jun 9, 2015
    510
    129
    30
    How to stop floodposting via batch?
     
  14. RobertJ

    RobertJ MDL Senior Member

    Apr 4, 2014
    318
    79
    10
    All very useful information, thanks! I plan to check the older versions in a VM later, but for now UBR is what I'm using (with set /a to convert it from hex to dec in batch).
     
  15. Garbellano

    Garbellano MDL Addicted

    Aug 13, 2012
    947
    248
    30
    #15 Garbellano, Nov 12, 2016
    Last edited by a moderator: Apr 20, 2017
    then a "proper" version would be

    Code:
    @echo off
    for /f "skip=2 tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuild') do set /a version=%%a
    for /f "skip=2 tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v UBR') do set /a mbn=%%a
    echo Windows Version: %version%.%mbn%
    
    
     
  16. RobertJ

    RobertJ MDL Senior Member

    Apr 4, 2014
    318
    79
    10
    #16 RobertJ, Nov 14, 2016
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Yeah, except CurrentBuild being a REG_SZ doesn't need /a with set, unlike UBR which is a REG_DWORD and returns a hex value.